summaryrefslogtreecommitdiff
path: root/tests/tiff
diff options
context:
space:
mode:
authorPierre Joye <pierre.php@gmail.com>2022-02-01 22:25:03 +0700
committerGitHub <noreply@github.com>2022-02-01 22:25:03 +0700
commit95c6185b3751a7b3d73093e1d9b67bb00a577cd2 (patch)
treea00634befbba1b04a64ec80a7071cb9ab318404e /tests/tiff
parent910924ffd78fd9ae13e27e2136316f8e49f4fcb1 (diff)
downloadlibgd-95c6185b3751a7b3d73093e1d9b67bb00a577cd2.tar.gz
Bug/818 (#821)
* Partial #818, unused arg * Partial #818, init var * partail #818, fix va_args usage * partail #818, handle f* calls and avoid possible call to malloc with negative values * partail #818, prevent double free * partail #818, resource leak if test fail * partail #818, null deref fix * partail #818, avoid double free on fp failure * Partial #818, fix error msg * Partial #818, leak on error * Partial #818, null deref * Partial #818, avoid possible negative index on failure * partial #818, does not free if we return if requested new size overflow * partial #818, avoid double free, free where the alloc happened * partial #818, fix assert logic and test exp_size for <=0 * partial #818, fix assert logic for color idx test * partial #818, new case for possible leak, improve logic * partial #818, fix assert logic for color idx test
Diffstat (limited to 'tests/tiff')
-rw-r--r--tests/tiff/tiff_invalid_read.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/tests/tiff/tiff_invalid_read.c b/tests/tiff/tiff_invalid_read.c
index 0d12918..3c87bcf 100644
--- a/tests/tiff/tiff_invalid_read.c
+++ b/tests/tiff/tiff_invalid_read.c
@@ -41,23 +41,35 @@ static size_t read_test_file(char **buffer, char *basename)
{
char *filename;
FILE *fp;
- size_t exp_size, act_size = -1;
+
+ size_t exp_size = 0, act_size = -1;
filename = gdTestFilePath2("tiff", basename);
fp = fopen(filename, "rb");
- if (gdTestAssert(fp != NULL)) goto fail3;
+ if (!gdTestAssert(fp != NULL)) goto fail3;
- if (fseek(fp, 0, SEEK_END) != 0) goto fail2;
+ if (fseek(fp, 0, SEEK_END) != 0) {
+ gdTestAssert(1==0); // only increase num failures used as return values in main
+ goto fail2;
+ }
exp_size = ftell(fp);
- if (gdTestAssert(exp_size <= 0)) goto fail2;
+ if (!gdTestAssert(exp_size > 0)) {
+ gdTestAssert(1==0); // only increase num failures used as return values in main
+ goto fail2;
+ }
- if (fseek(fp, 0, SEEK_SET) != 0) goto fail2;
+ if (fseek(fp, 0, SEEK_SET) != 0) {
+ gdTestAssert(1==0); // only increase num failures used as return values in main
+ goto fail2;
+ }
*buffer = malloc(exp_size);
- if (gdTestAssert(*buffer != NULL)) goto fail2;
- act_size = fread(*buffer, sizeof(**buffer), exp_size, fp);
- gdTestAssert(act_size == exp_size);
+ if (gdTestAssert(*buffer != NULL)) {
+ act_size = fread(*buffer, sizeof(**buffer), exp_size, fp);
+ gdTestAssert(act_size == exp_size);
+ }
+
fail2:
fclose(fp);