Created
March 22, 2022 19:58
-
-
Save moyix/e5398f6f535b17e1df26e877b74f28bc to your computer and use it in GitHub Desktop.
Buggy code from libtiff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int readSeparateTilesIntoBuffer (TIFF* in, uint8 *obuf, | |
uint32 imagelength, uint32 imagewidth, | |
uint32 tw, uint32 tl, | |
uint16 spp, uint16 bps) | |
{ | |
int i, status = 1, sample; | |
int shift_width, bytes_per_pixel; | |
uint16 bytes_per_sample; | |
uint32 row, col; /* Current row and col of image */ | |
uint32 nrow, ncol; /* Number of rows and cols in current tile */ | |
uint32 row_offset, col_offset; /* Output buffer offsets */ | |
tsize_t tbytes = 0, tilesize = TIFFTileSize(in); | |
tsample_t s; | |
uint8* bufp = (uint8*)obuf; | |
unsigned char *srcbuffs[MAX_SAMPLES]; | |
unsigned char *tbuff = NULL; | |
bytes_per_sample = (bps + 7) / 8; | |
for (sample = 0; (sample < spp) && (sample < MAX_SAMPLES); sample++) | |
{ | |
srcbuffs[sample] = NULL; | |
tbuff = (unsigned char *)_TIFFmalloc(tilesize + 8); | |
if (!tbuff) | |
{ | |
TIFFError ("readSeparateTilesIntoBuffer", | |
"Unable to allocate tile read buffer for sample %d", sample); | |
for (i = 0; i < sample; i++) | |
_TIFFfree (srcbuffs[i]); | |
return 0; | |
} | |
srcbuffs[sample] = tbuff; | |
} | |
/* Each tile contains only the data for a single plane | |
* arranged in scanlines of tw * bytes_per_sample bytes. | |
*/ | |
for (row = 0; row < imagelength; row += tl) | |
{ | |
nrow = (row + tl > imagelength) ? imagelength - row : tl; | |
for (col = 0; col < imagewidth; col += tw) | |
{ | |
for (s = 0; s < spp; s++) | |
{ // Read each plane of a tile set into srcbuffs[s] | |
tbytes = TIFFReadTile(in, srcbuffs[s], col, row, 0, s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment