diff options
Diffstat (limited to 'source/blender/imbuf/intern/jpeg.c')
-rw-r--r-- | source/blender/imbuf/intern/jpeg.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index d23223e4c11..32dae3c982e 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -29,6 +29,11 @@ * $Id$ */ +/** \file blender/imbuf/intern/jpeg.c + * \ingroup imbuf + */ + + /* This little block needed for linking to Blender... */ #include <stdio.h> @@ -158,8 +163,11 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) my_src_ptr src = (my_src_ptr) cinfo->src; if(num_bytes > 0) { - src->pub.next_input_byte = src->pub.next_input_byte + num_bytes; - src->pub.bytes_in_buffer = src->pub.bytes_in_buffer - num_bytes; + // prevent skipping over file end + size_t skip_size = (size_t)num_bytes <= src->pub.bytes_in_buffer ? num_bytes : src->pub.bytes_in_buffer; + + src->pub.next_input_byte = src->pub.next_input_byte + skip_size; + src->pub.bytes_in_buffer = src->pub.bytes_in_buffer - skip_size; } } @@ -217,17 +225,19 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t */ #define MAKE_BYTE_AVAIL(cinfo,action) \ if (bytes_in_buffer == 0) { \ - if (! (*datasrc->fill_input_buffer) (cinfo)) \ - { action; } \ - INPUT_RELOAD(cinfo); \ - } \ - bytes_in_buffer-- + if (! (*datasrc->fill_input_buffer) (cinfo)) \ + { action; } \ + INPUT_RELOAD(cinfo); \ + } + + /* Read a byte into variable V. * If must suspend, take the specified action (typically "return FALSE"). */ #define INPUT_BYTE(cinfo,V,action) \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ + bytes_in_buffer--; \ V = GETJOCTET(*next_input_byte++); ) /* As above, but read two bytes interpreted as an unsigned 16-bit integer. @@ -235,8 +245,10 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t */ #define INPUT_2BYTES(cinfo,V,action) \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ + bytes_in_buffer--; \ V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \ MAKE_BYTE_AVAIL(cinfo,action); \ + bytes_in_buffer--; \ V += GETJOCTET(*next_input_byte++); ) @@ -247,7 +259,8 @@ handle_app1 (j_decompress_ptr cinfo) char neogeo[128]; INPUT_VARS(cinfo); - + + length = 0; INPUT_2BYTES(cinfo, length, return FALSE); length -= 2; @@ -266,10 +279,10 @@ handle_app1 (j_decompress_ptr cinfo) static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int flags) { JSAMPARRAY row_pointer; - JSAMPLE * buffer = 0; + JSAMPLE * buffer = NULL; int row_stride; int x, y, depth, r, g, b, k; - struct ImBuf * ibuf = 0; + struct ImBuf * ibuf = NULL; uchar * rect; jpeg_saved_marker_ptr marker; char *str, *key, *value; @@ -465,7 +478,7 @@ ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags) static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf) { - JSAMPLE * buffer = 0; + JSAMPLE * buffer = NULL; JSAMPROW row_pointer[1]; uchar * rect; int x, y; |