mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-19 20:08:28 +01:00
ImgIoUtilReadFile: check ftell() return
This avoids attempting to allocate 0 bytes if the call fails. (An additional byte is added to the result to allow a '\0' to be appended.) Bug: chromium:334120888 Change-Id: Ifcb8ff7744c567cbd08051aa04cc66acf936078d
This commit is contained in:
parent
dc9505855e
commit
3cada4cef4
@ -89,6 +89,11 @@ int ImgIoUtilReadFile(const char* const file_name,
|
|||||||
}
|
}
|
||||||
fseek(in, 0, SEEK_END);
|
fseek(in, 0, SEEK_END);
|
||||||
file_size = ftell(in);
|
file_size = ftell(in);
|
||||||
|
if (file_size == (size_t)-1) {
|
||||||
|
fclose(in);
|
||||||
|
WFPRINTF(stderr, "error getting size of '%s'\n", (const W_CHAR*)file_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
fseek(in, 0, SEEK_SET);
|
fseek(in, 0, SEEK_SET);
|
||||||
// we allocate one extra byte for the \0 terminator
|
// we allocate one extra byte for the \0 terminator
|
||||||
file_data = (uint8_t*)WebPMalloc(file_size + 1);
|
file_data = (uint8_t*)WebPMalloc(file_size + 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user