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
+16 -11
View File
@@ -113,18 +113,23 @@ struct fpk *fpk_open(const char *path)
goto fail; goto fail;
strtab_size = dir_offset - strtab_offset; strtab_size = dir_offset - strtab_offset;
fpk->strtab = malloc((size_t)strtab_size); if (strtab_size > 0) {
if (fpk->strtab == NULL) fpk->strtab = malloc((size_t)strtab_size);
goto fail; if (fpk->strtab == NULL)
if (fpk_fseek64(fpk->file, strtab_offset) != 0) goto fail;
goto fail; if (fpk_fseek64(fpk->file, strtab_offset) != 0)
if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) != goto fail;
strtab_size) if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) !=
goto fail; strtab_size)
goto fail;
}
fpk->entries = malloc((size_t)fpk->entry_count * sizeof(fpk_entry_t)); if (fpk->entry_count > 0) {
if (fpk->entries == NULL) fpk->entries = malloc(
goto fail; (size_t)fpk->entry_count * sizeof(fpk_entry_t));
if (fpk->entries == NULL)
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++) {