From 66386d5ac417ff0e1818dee1422e9c445820b226 Mon Sep 17 00:00:00 2001 From: sezero Date: Wed, 22 Aug 2018 02:24:24 +0300 Subject: [PATCH] h5, g3df.c: fix wrong error fread() checks. commit 4b63afa8 by jwrdegoede added fread() checks like: if(fread(buf,size,nelem,fp) != size*nelem) error(); however the check must be against nelem alone, and _not_ the total bytes. --- glide3x/cvg/glide3/src/g3df.c | 3 +-- glide3x/h3/glide3/src/g3df.c | 3 +-- glide3x/h5/glide3/src/g3df.c | 12 ++++-------- glide3x/sst1/glide3/src/g3df.c | 3 +-- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/glide3x/cvg/glide3/src/g3df.c b/glide3x/cvg/glide3/src/g3df.c index 6aa0b1b..e4dcb04 100644 --- a/glide3x/cvg/glide3/src/g3df.c +++ b/glide3x/cvg/glide3/src/g3df.c @@ -617,8 +617,7 @@ Read8Bit(FxU8 *data, FILE *image_file, width = _grMipMapHostWH[aspect_ratio][lod][0]; height = _grMipMapHostWH[aspect_ratio][lod][1]; - if (fread(data, sizeof(char), width*height, image_file) != - (sizeof(char)*width*height)) + if (fread(data, 1, width*height, image_file) != (width*height)) return FXFALSE; data += width*height; } diff --git a/glide3x/h3/glide3/src/g3df.c b/glide3x/h3/glide3/src/g3df.c index ca69bd0..e2c4e9f 100644 --- a/glide3x/h3/glide3/src/g3df.c +++ b/glide3x/h3/glide3/src/g3df.c @@ -622,8 +622,7 @@ Read8Bit(FxU8 *data, FILE *image_file, width = _grMipMapHostWH[aspect_ratio][lod][0]; height = _grMipMapHostWH[aspect_ratio][lod][1]; - if (fread(data, sizeof(char), width*height, image_file) != - (sizeof(char)*width*height)) + if (fread(data, 1, width*height, image_file) != (width*height)) return FXFALSE; data += width*height; } diff --git a/glide3x/h5/glide3/src/g3df.c b/glide3x/h5/glide3/src/g3df.c index 76d9683..d511201 100644 --- a/glide3x/h5/glide3/src/g3df.c +++ b/glide3x/h5/glide3/src/g3df.c @@ -969,8 +969,7 @@ Read4Bit(FxU8 *data, FILE *image_file, int small_lod, int large_lod, read 16 bytes at a time. */ thisMipMapByteCount = (width * height) >> 5; - if (fread(data, 16, thisMipMapByteCount, image_file) != - (16*thisMipMapByteCount)) + if (fread(data, 16, thisMipMapByteCount, image_file) != thisMipMapByteCount) return FXFALSE; data += (16 * thisMipMapByteCount); } @@ -1001,8 +1000,7 @@ ReadDXT4Bit(FxU8 *data, FILE *image_file, int small_lod, int large_lod, /* Divide the WxH by 16 to read 8 bytes at a time. */ thisMipMapByteCount = (width * height) >> 4; - if (fread(data, 8, thisMipMapByteCount, image_file) != - (8 * thisMipMapByteCount)) + if (fread(data, 8, thisMipMapByteCount, image_file) != thisMipMapByteCount) return FXFALSE; data += (8 * thisMipMapByteCount); } @@ -1033,8 +1031,7 @@ ReadDXT8Bit(FxU8 *data, FILE *image_file, read 16 bytes at a time. */ thisMipMapByteCount = (width * height) >> 4; - if (fread(data, 16, thisMipMapByteCount, image_file) != - (16 * thisMipMapByteCount)) + if (fread(data, 16, thisMipMapByteCount, image_file) != thisMipMapByteCount) return FXFALSE; data += (16 * thisMipMapByteCount); } @@ -1061,8 +1058,7 @@ Read8Bit(FxU8 *data, FILE *image_file, thisMipMapByteCount = width * height; - if (fread(data, sizeof(char), thisMipMapByteCount, image_file) != - (sizeof(char) * thisMipMapByteCount)) + if (fread(data, 1, thisMipMapByteCount, image_file) != thisMipMapByteCount) return FXFALSE; data += thisMipMapByteCount; } diff --git a/glide3x/sst1/glide3/src/g3df.c b/glide3x/sst1/glide3/src/g3df.c index a98a5eb..5d5ff0f 100644 --- a/glide3x/sst1/glide3/src/g3df.c +++ b/glide3x/sst1/glide3/src/g3df.c @@ -515,8 +515,7 @@ Read8Bit(FxU8 *data, FILE *image_file, width = _grMipMapHostWH[aspect_ratio][lod][0]; height = _grMipMapHostWH[aspect_ratio][lod][1]; - if (fread(data, sizeof(char), width*height, image_file) != - (sizeof(char)*width*height)) + if (fread(data, 1, width*height, image_file) != (width*height)) return FXFALSE; data += width*height; }