fix: avoid failing open on empty archives (malloc(0) returns NULL)
This commit is contained in:
@@ -113,18 +113,23 @@ struct fpk *fpk_open(const char *path)
|
||||
goto fail;
|
||||
strtab_size = dir_offset - strtab_offset;
|
||||
|
||||
fpk->strtab = malloc((size_t)strtab_size);
|
||||
if (fpk->strtab == NULL)
|
||||
goto fail;
|
||||
if (fpk_fseek64(fpk->file, strtab_offset) != 0)
|
||||
goto fail;
|
||||
if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) !=
|
||||
strtab_size)
|
||||
goto fail;
|
||||
if (strtab_size > 0) {
|
||||
fpk->strtab = malloc((size_t)strtab_size);
|
||||
if (fpk->strtab == NULL)
|
||||
goto fail;
|
||||
if (fpk_fseek64(fpk->file, strtab_offset) != 0)
|
||||
goto fail;
|
||||
if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) !=
|
||||
strtab_size)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fpk->entries = malloc((size_t)fpk->entry_count * sizeof(fpk_entry_t));
|
||||
if (fpk->entries == NULL)
|
||||
goto fail;
|
||||
if (fpk->entry_count > 0) {
|
||||
fpk->entries = malloc(
|
||||
(size_t)fpk->entry_count * sizeof(fpk_entry_t));
|
||||
if (fpk->entries == NULL)
|
||||
goto fail;
|
||||
}
|
||||
if (fpk_fseek64(fpk->file, dir_offset) != 0)
|
||||
goto fail;
|
||||
for (i = 0; i < fpk->entry_count; i++) {
|
||||
|
||||
Reference in New Issue
Block a user