Merge pull request #107 from lovell/master

Use static buffer for fake JPEG EOI marker as src->buf might not be allocated
This commit is contained in:
John Cupitt 2014-02-24 21:42:46 +00:00
commit 35d15b07a2
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;
}
/* 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.
*
@ -1105,23 +1109,19 @@ static boolean
fill_input_buffer (j_decompress_ptr cinfo)
{
InputBuffer *src = (InputBuffer *) cinfo->src;
size_t nbytes;
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 {
WARNMS(cinfo, JWRN_JPEG_EOF);
/* Insert a fake EOI marker */
src->buf[0] = (JOCTET) 0xFF;
src->buf[1] = (JOCTET) JPEG_EOI;
nbytes = 2;
src->pub.next_input_byte = EOI_BUFFER;
src->pub.bytes_in_buffer = 1;
}
src->pub.next_input_byte = src->buf;
src->pub.bytes_in_buffer = nbytes;
src->start_of_file = FALSE;
return TRUE;
}