tiff2pdf: get rid of uninitialized memory content

fixes #176
This commit is contained in:
Thomas Bernard 2020-04-05 00:01:59 +02:00
parent 1b4708f67f
commit bb1ab756d6
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -2282,6 +2282,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
TIFFReadRawStrip(input, 0, (tdata_t) buffer, TIFFReadRawStrip(input, 0, (tdata_t) buffer,
t2p->tiff_datasize); t2p->tiff_datasize);
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){ if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){
@ -2310,7 +2311,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize);
TIFFReadRawStrip(input, 0, (tdata_t) buffer, TIFFReadRawStrip(input, 0, (tdata_t) buffer,
t2p->tiff_datasize); t2p->tiff_datasize);
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB) { if (t2p->tiff_fillorder==FILLORDER_LSB2MSB) {
@ -2337,7 +2338,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize);
if(t2p->pdf_ojpegiflength==0){ if(t2p->pdf_ojpegiflength==0){
inputoffset=t2pSeekFile(input, 0, inputoffset=t2pSeekFile(input, 0,
SEEK_CUR); SEEK_CUR);
@ -2413,7 +2414,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize);
_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength); _TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);
bufferoffset=t2p->pdf_ojpegdatalength; bufferoffset=t2p->pdf_ojpegdatalength;
stripcount=TIFFNumberOfStrips(input); stripcount=TIFFNumberOfStrips(input);
@ -2462,7 +2463,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize);
if (TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) { if (TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {
if(count > 4) { if(count > 4) {
_TIFFmemcpy(buffer, jpt, count); _TIFFmemcpy(buffer, jpt, count);
@ -2485,6 +2486,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(stripbuffer, 0, max_striplength);
for(i=0;i<stripcount;i++){ for(i=0;i<stripcount;i++){
striplength=TIFFReadRawStrip(input, i, (tdata_t) stripbuffer, -1); striplength=TIFFReadRawStrip(input, i, (tdata_t) stripbuffer, -1);
if(!t2p_process_jpeg_strip( if(!t2p_process_jpeg_strip(
@ -2525,7 +2527,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize);
stripsize=TIFFStripSize(input); stripsize=TIFFStripSize(input);
stripcount=TIFFNumberOfStrips(input); stripcount=TIFFNumberOfStrips(input);
for(i=0;i<stripcount;i++){ for(i=0;i<stripcount;i++){
@ -2563,7 +2565,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize);
samplebuffer = (unsigned char*) _TIFFmalloc(stripsize); samplebuffer = (unsigned char*) _TIFFmalloc(stripsize);
if(samplebuffer==NULL){ if(samplebuffer==NULL){
TIFFError(TIFF2PDF_MODULE, TIFFError(TIFF2PDF_MODULE,
@ -2613,7 +2615,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize);
stripsize=TIFFStripSize(input); stripsize=TIFFStripSize(input);
stripcount=TIFFNumberOfStrips(input); stripcount=TIFFNumberOfStrips(input);
for(i=0;i<stripcount;i++){ for(i=0;i<stripcount;i++){
@ -2877,6 +2879,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize); TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){ if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){
TIFFReverseBits(buffer, t2p->tiff_datasize); TIFFReverseBits(buffer, t2p->tiff_datasize);
@ -2898,6 +2901,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize); TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){ if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){
TIFFReverseBits(buffer, t2p->tiff_datasize); TIFFReverseBits(buffer, t2p->tiff_datasize);
@ -2927,6 +2931,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength); _TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);
if(edge!=0){ if(edge!=0){
if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){ if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){
@ -2968,6 +2973,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) { if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {
if (count > 4) { if (count > 4) {
int retTIFFReadRawTile; int retTIFFReadRawTile;
@ -3016,6 +3022,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
read = TIFFReadEncodedTile( read = TIFFReadEncodedTile(
input, input,
@ -3049,6 +3056,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
samplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); samplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
if(samplebuffer==NULL){ if(samplebuffer==NULL){
TIFFError(TIFF2PDF_MODULE, TIFFError(TIFF2PDF_MODULE,
@ -3060,6 +3068,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(samplebuffer, 0, t2p->tiff_datasize);
samplebufferoffset=0; samplebufferoffset=0;
for(i=0;i<t2p->tiff_samplesperpixel;i++){ for(i=0;i<t2p->tiff_samplesperpixel;i++){
read = read =
@ -3099,6 +3108,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR; t2p->t2p_error = T2P_ERR_ERROR;
return(0); return(0);
} }
memset(buffer, 0, t2p->tiff_datasize);
read = TIFFReadEncodedTile( read = TIFFReadEncodedTile(
input, input,
tile, tile,