From c529793fdb60a4b58e6914c4aa0e58e34f688f56 Mon Sep 17 00:00:00 2001 From: ludwig Date: Thu, 14 Feb 2008 11:13:42 +0000 Subject: don't read more memory than available in jpg decode git-svn-id: svn://svn.icculus.org/quake3/trunk@1259 edf5b092-35ff-0310-97b2-ce42778d08ea --- code/renderer/tr_image_jpg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'code/renderer') diff --git a/code/renderer/tr_image_jpg.c b/code/renderer/tr_image_jpg.c index cae7ccb..9add7dd 100644 --- a/code/renderer/tr_image_jpg.c +++ b/code/renderer/tr_image_jpg.c @@ -56,6 +56,7 @@ void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height unsigned row_stride; /* physical row width in output buffer */ unsigned pixelcount, memcount; unsigned char *out; + int len; byte *fbuffer; byte *buf; @@ -65,8 +66,8 @@ void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height * requires it in order to read binary files. */ - ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer); - if (!fbuffer) { + len = ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer); + if (!fbuffer || len < 0) { return; } @@ -84,7 +85,7 @@ void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height /* Step 2: specify data source (eg, a file) */ - jpeg_stdio_src(&cinfo, fbuffer); + jpeg_mem_src(&cinfo, fbuffer, len); /* Step 3: read file parameters with jpeg_read_header() */ -- cgit v1.2.3