fix: avoid failing open on empty archives (malloc(0) returns NULL)

This commit is contained in:
2026-09-15 10:52:03 +02:00
parent c08d3b097a
commit 4b5f67c0ba
+6 -1
View File
@@ -113,6 +113,7 @@ struct fpk *fpk_open(const char *path)
goto fail; goto fail;
strtab_size = dir_offset - strtab_offset; strtab_size = dir_offset - strtab_offset;
if (strtab_size > 0) {
fpk->strtab = malloc((size_t)strtab_size); fpk->strtab = malloc((size_t)strtab_size);
if (fpk->strtab == NULL) if (fpk->strtab == NULL)
goto fail; goto fail;
@@ -121,10 +122,14 @@ struct fpk *fpk_open(const char *path)
if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) != if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) !=
strtab_size) strtab_size)
goto fail; goto fail;
}
fpk->entries = malloc((size_t)fpk->entry_count * sizeof(fpk_entry_t)); if (fpk->entry_count > 0) {
fpk->entries = malloc(
(size_t)fpk->entry_count * sizeof(fpk_entry_t));
if (fpk->entries == NULL) if (fpk->entries == NULL)
goto fail; goto fail;
}
if (fpk_fseek64(fpk->file, dir_offset) != 0) if (fpk_fseek64(fpk->file, dir_offset) != 0)
goto fail; goto fail;
for (i = 0; i < fpk->entry_count; i++) { for (i = 0; i < fpk->entry_count; i++) {