Coverage Report

Created: 2026-01-09 06:28

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