2016-04-16 00:51:22 -07:00
|
|
|
/* Just try to read the invalid gd2 image & not crash. */
|
|
|
|
#include "gd.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "gdtest.h"
|
|
|
|
|
Fix tests based on coverity reports (#819)
* 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
2022-02-01 00:09:01 -08:00
|
|
|
int main()
|
2016-04-16 00:51:22 -07:00
|
|
|
{
|
|
|
|
gdImagePtr im;
|
|
|
|
FILE *fp;
|
2016-04-30 18:52:45 -07:00
|
|
|
|
2016-07-13 23:47:07 -07:00
|
|
|
fp = gdTestFileOpen2("gd2", "invalid_header.gd2");
|
2016-04-16 00:51:22 -07:00
|
|
|
|
|
|
|
if (!fp) {
|
2016-07-17 01:49:09 -07:00
|
|
|
gdTestErrorMsg("failed, cannot open file: %s\n", "invalid_header.gd2");
|
2016-04-16 00:51:22 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
im = gdImageCreateFromGd2(fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
2016-07-13 23:47:07 -07:00
|
|
|
if (im != NULL) {
|
|
|
|
gdTestErrorMsg("image should have failed to be loaded\n");
|
|
|
|
gdImageDestroy(im);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-16 00:51:22 -07:00
|
|
|
}
|