Coverage Report

Created: 2025-07-11 06:59

/src/qpdf/libqpdf/QPDFObject.cc
Line
Count
Source (jump to first uncovered line)
1
#include <qpdf/QPDFObject_private.hh>
2
3
std::string
4
QPDFObject::getDescription()
5
220k
{
6
220k
    qpdf_offset_t shift = (getTypeCode() == ::ot_dictionary) ? 2
7
220k
        : (getTypeCode() == ::ot_array)                      ? 1
8
181k
                                                             : 0;
9
10
220k
    if (object_description) {
11
92.9k
        switch (object_description->index()) {
12
87.2k
        case 0:
13
87.2k
            {
14
                // Simple template string
15
87.2k
                auto description = std::get<0>(*object_description);
16
17
87.2k
                if (auto pos = description.find("$OG"); pos != std::string::npos) {
18
0
                    description.replace(pos, 3, og.unparse(' '));
19
0
                }
20
87.2k
                if (auto pos = description.find("$PO"); pos != std::string::npos) {
21
75.3k
                    description.replace(pos, 3, std::to_string(parsed_offset + shift));
22
75.3k
                }
23
87.2k
                return description;
24
0
            }
25
0
        case 1:
26
0
            {
27
                // QPDF::JSONReactor generated description
28
0
                auto j_descr = std::get<1>(*object_description);
29
0
                return (
30
0
                    *j_descr.input + (j_descr.object.empty() ? "" : ", " + j_descr.object) +
31
0
                    " at offset " + std::to_string(parsed_offset));
32
0
            }
33
4.95k
        case 2:
34
4.95k
            {
35
                // Child object description
36
4.95k
                auto j_descr = std::get<2>(*object_description);
37
4.95k
                std::string result;
38
4.95k
                if (auto p = j_descr.parent.lock()) {
39
4.95k
                    result = p->getDescription();
40
4.95k
                }
41
4.95k
                result += j_descr.static_descr;
42
4.95k
                if (auto pos = result.find("$VD"); pos != std::string::npos) {
43
4.95k
                    result.replace(pos, 3, j_descr.var_descr);
44
4.95k
                }
45
4.95k
                return result;
46
0
            }
47
657
        case 3:
48
657
            auto [stream_id, obj_id] = std::get<3>(*object_description);
49
657
            std::string result = qpdf ? qpdf->getFilename() : "";
50
657
            result += " object stream " + std::to_string(stream_id) + ", object " +
51
657
                std::to_string(obj_id) + " 0 at offset " + std::to_string(parsed_offset + shift);
52
657
            return result;
53
92.9k
        }
54
55
127k
    } else if (og.isIndirect()) {
56
68.3k
        return "object " + og.unparse(' ');
57
68.3k
    }
58
58.9k
    return {};
59
220k
}