Use static buffer for fake JPEG EOI marker as src->buf might not be allocated

Discovered whilst investigating lovell/sharp#6
This commit is contained in:
Lovell Fuller 2014-02-22 12:45:18 +00:00
parent 76b2fa9732
commit 854eab527a
1 changed files with 9 additions and 9 deletions

View File

@ -1068,6 +1068,10 @@ init_source (j_decompress_ptr cinfo)
src->start_of_file = TRUE; src->start_of_file = TRUE;
} }
/* Buffer containing fake EOI marker, used by fill_input_buffer.
*/
const static JOCTET EOI_BUFFER[1] = { JPEG_EOI };
/* /*
* Fill the input buffer --- called whenever buffer is emptied. * Fill the input buffer --- called whenever buffer is emptied.
* *
@ -1105,23 +1109,19 @@ static boolean
fill_input_buffer (j_decompress_ptr cinfo) fill_input_buffer (j_decompress_ptr cinfo)
{ {
InputBuffer *src = (InputBuffer *) cinfo->src; InputBuffer *src = (InputBuffer *) cinfo->src;
size_t nbytes;
if (src->start_of_file) { if (src->start_of_file) {
nbytes = src->len; src->pub.next_input_byte = src->buf;
src->pub.bytes_in_buffer = src->len;
src->start_of_file = FALSE;
} }
else { else {
WARNMS(cinfo, JWRN_JPEG_EOF); WARNMS(cinfo, JWRN_JPEG_EOF);
/* Insert a fake EOI marker */ /* Insert a fake EOI marker */
src->buf[0] = (JOCTET) 0xFF; src->pub.next_input_byte = EOI_BUFFER;
src->buf[1] = (JOCTET) JPEG_EOI; src->pub.bytes_in_buffer = 1;
nbytes = 2;
} }
src->pub.next_input_byte = src->buf;
src->pub.bytes_in_buffer = nbytes;
src->start_of_file = FALSE;
return TRUE; return TRUE;
} }