Coverage Report

Created: 2026-07-16 06:57

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
2.13k
    proxied(proxied),
14
2.13k
    global_offset(global_offset)
15
2.13k
{
16
2.13k
    util::assertion(global_offset >= 0, "OffsetInputSource constructed with negative offset");
17
2.13k
    max_safe_offset = std::numeric_limits<qpdf_offset_t>::max() - global_offset;
18
2.13k
}
19
20
qpdf_offset_t
21
OffsetInputSource::findAndSkipNextEOL()
22
895k
{
23
895k
    return proxied->findAndSkipNextEOL() - global_offset;
24
895k
}
25
26
std::string const&
27
OffsetInputSource::getName() const
28
148k
{
29
148k
    return proxied->getName();
30
148k
}
31
32
qpdf_offset_t
33
OffsetInputSource::tell()
34
7.00M
{
35
7.00M
    return proxied->tell() - global_offset;
36
7.00M
}
37
38
void
39
OffsetInputSource::seek(qpdf_offset_t offset, int whence)
40
2.59M
{
41
2.59M
    if (whence == SEEK_SET) {
42
2.55M
        if (offset > max_safe_offset) {
43
8
            std::ostringstream msg;
44
8
            msg.imbue(std::locale::classic());
45
8
            msg << "seeking to " << offset << " offset by " << global_offset
46
8
                << " would cause an overflow of the offset type";
47
8
            throw std::range_error(msg.str());
48
8
        }
49
2.55M
        proxied->seek(offset + global_offset, whence);
50
2.55M
    } else {
51
34.1k
        proxied->seek(offset, whence);
52
34.1k
    }
53
2.59M
    util::no_ci_rt_error_if(tell() < 0, "offset input source: seek before beginning of file");
54
2.59M
}
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
641k
{
65
641k
    size_t result = proxied->read(buffer, length);
66
641k
    setLastOffset(proxied->getLastOffset() - global_offset);
67
641k
    return result;
68
641k
}
69
70
void
71
OffsetInputSource::unreadCh(char ch)
72
1.16k
{
73
1.16k
    proxied->unreadCh(ch);
74
1.16k
}