Coverage Report

Created: 2026-06-15 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qpdf/libqpdf/OffsetInputSource.cc
Line
Count
Source
1
#include <qpdf/OffsetInputSource.hh>
2
3
#include <qpdf/Util.hh>
4
5
#include <limits>
6
#include <sstream>
7
#include <stdexcept>
8
9
using namespace qpdf;
10
11
OffsetInputSource::OffsetInputSource(
12
    std::shared_ptr<InputSource> proxied, qpdf_offset_t global_offset) :
13
14.8k
    proxied(proxied),
14
14.8k
    global_offset(global_offset)
15
14.8k
{
16
14.8k
    util::assertion(global_offset >= 0, "OffsetInputSource constructed with negative offset");
17
14.8k
    max_safe_offset = std::numeric_limits<qpdf_offset_t>::max() - global_offset;
18
14.8k
}
19
20
qpdf_offset_t
21
OffsetInputSource::findAndSkipNextEOL()
22
4.86M
{
23
4.86M
    return proxied->findAndSkipNextEOL() - global_offset;
24
4.86M
}
25
26
std::string const&
27
OffsetInputSource::getName() const
28
1.19M
{
29
1.19M
    return proxied->getName();
30
1.19M
}
31
32
qpdf_offset_t
33
OffsetInputSource::tell()
34
55.1M
{
35
55.1M
    return proxied->tell() - global_offset;
36
55.1M
}
37
38
void
39
OffsetInputSource::seek(qpdf_offset_t offset, int whence)
40
22.4M
{
41
22.4M
    if (whence == SEEK_SET) {
42
22.1M
        if (offset > max_safe_offset) {
43
68
            std::ostringstream msg;
44
68
            msg.imbue(std::locale::classic());
45
68
            msg << "seeking to " << offset << " offset by " << global_offset
46
68
                << " would cause an overflow of the offset type";
47
68
            throw std::range_error(msg.str());
48
68
        }
49
22.1M
        proxied->seek(offset + global_offset, whence);
50
22.1M
    } else {
51
292k
        proxied->seek(offset, whence);
52
292k
    }
53
22.4M
    util::no_ci_rt_error_if(tell() < 0, "offset input source: seek before beginning of file");
54
22.4M
}
55
56
void
57
OffsetInputSource::rewind()
58
0
{
59
0
    seek(0, SEEK_SET);
60
0
}
61
62
size_t
63
OffsetInputSource::read(char* buffer, size_t length)
64
6.22M
{
65
6.22M
    size_t result = proxied->read(buffer, length);
66
6.22M
    setLastOffset(proxied->getLastOffset() - global_offset);
67
6.22M
    return result;
68
6.22M
}
69
70
void
71
OffsetInputSource::unreadCh(char ch)
72
9.06k
{
73
9.06k
    proxied->unreadCh(ch);
74
9.06k
}