Coverage Report

Created: 2026-06-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libtiff/libtiff/tif_dumpmode.c
Line
Count
Source
1
/*
2
 * Copyright (c) 1988-1997 Sam Leffler
3
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software and
6
 * its documentation for any purpose is hereby granted without fee, provided
7
 * that (i) the above copyright notices and this permission notice appear in
8
 * all copies of the software and related documentation, and (ii) the names of
9
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10
 * publicity relating to the software without the specific, prior written
11
 * permission of Sam Leffler and Silicon Graphics.
12
 *
13
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16
 *
17
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22
 * OF THIS SOFTWARE.
23
 */
24
25
/*
26
 * TIFF Library.
27
 *
28
 * "Null" Compression Algorithm Support.
29
 */
30
#include "tiffiop.h"
31
32
static int DumpFixupTags(TIFF *tif)
33
118k
{
34
118k
    (void)tif;
35
118k
    return (1);
36
118k
}
37
38
/*
39
 * Encode a hunk of pixels.
40
 */
41
static int DumpModeEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
42
804k
{
43
804k
    (void)s;
44
1.60M
    while (cc > 0)
45
804k
    {
46
804k
        tmsize_t n;
47
48
804k
        n = cc;
49
804k
        if (tif->tif_rawcc + n > tif->tif_rawdatasize)
50
0
            n = tif->tif_rawdatasize - tif->tif_rawcc;
51
52
804k
        assert(n > 0);
53
54
        /*
55
         * Avoid copy if client has setup raw
56
         * data buffer to avoid extra copy.
57
         */
58
804k
        if (tif->tif_rawcp != pp)
59
804k
            _TIFFmemcpy(tif->tif_rawcp, pp, n);
60
804k
        tif->tif_rawcp += n;
61
804k
        tif->tif_rawcc += n;
62
804k
        pp += n;
63
804k
        cc -= n;
64
804k
        if (tif->tif_rawcc >= tif->tif_rawdatasize && !TIFFFlushData1(tif))
65
0
            return (0);
66
804k
    }
67
804k
    return (1);
68
804k
}
69
70
/*
71
 * Decode a hunk of pixels.
72
 */
73
static int DumpModeDecode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
74
2.47M
{
75
2.47M
    static const char module[] = "DumpModeDecode";
76
2.47M
    (void)s;
77
2.47M
    if (tif->tif_rawcc < cc)
78
17.8k
    {
79
17.8k
        TIFFErrorExtR(tif, module,
80
17.8k
                      "Not enough data for scanline %" PRIu32
81
17.8k
                      ", expected a request for at most %" TIFF_SSIZE_FORMAT
82
17.8k
                      " bytes, got a request for %" TIFF_SSIZE_FORMAT " bytes",
83
17.8k
                      tif->tif_dir.td_row, tif->tif_rawcc, cc);
84
17.8k
        return (0);
85
17.8k
    }
86
    /*
87
     * Avoid copy if client has setup raw
88
     * data buffer to avoid extra copy.
89
     */
90
2.45M
    if (tif->tif_rawcp != buf)
91
2.45M
        _TIFFmemcpy(buf, tif->tif_rawcp, cc);
92
2.45M
    tif->tif_rawcp += cc;
93
2.45M
    tif->tif_rawcc -= cc;
94
2.45M
    return (1);
95
2.47M
}
96
97
/*
98
 * Seek forwards nrows in the current strip.
99
 */
100
static int DumpModeSeek(TIFF *tif, uint32_t nrows)
101
0
{
102
0
    tmsize_t seek_size;
103
0
    if (nrows > 0 &&
104
0
        tif->tif_dir.td_scanlinesize > (tmsize_t)(TIFF_TMSIZE_T_MAX / nrows))
105
0
    {
106
0
        TIFFErrorExtR(tif, "DumpModeSeek",
107
0
                      "Integer overflow computing seek size");
108
0
        return (0);
109
0
    }
110
0
    seek_size = (tmsize_t)nrows * tif->tif_dir.td_scanlinesize;
111
0
    if (seek_size > tif->tif_rawcc)
112
0
    {
113
0
        TIFFErrorExtR(tif, "DumpModeSeek",
114
0
                      "Seek beyond end of raw data buffer");
115
0
        return (0);
116
0
    }
117
0
    tif->tif_rawcp += seek_size;
118
0
    tif->tif_rawcc -= seek_size;
119
0
    return (1);
120
0
}
121
122
/*
123
 * Initialize dump mode.
124
 */
125
int TIFFInitDumpMode(TIFF *tif, int scheme)
126
856k
{
127
856k
    (void)scheme;
128
856k
    tif->tif_fixuptags = DumpFixupTags;
129
856k
    tif->tif_decoderow = DumpModeDecode;
130
856k
    tif->tif_decodestrip = DumpModeDecode;
131
856k
    tif->tif_decodetile = DumpModeDecode;
132
856k
    tif->tif_encoderow = DumpModeEncode;
133
856k
    tif->tif_encodestrip = DumpModeEncode;
134
856k
    tif->tif_encodetile = DumpModeEncode;
135
856k
    tif->tif_seek = DumpModeSeek;
136
856k
    return (1);
137
856k
}