A pattern I keep finding in reviews:
size_t n = read_count_from_header();
struct item *p = malloc(n * sizeof *p);
if (!p) return -1;
for (size_t i = 0; i < n; i++)
p[i] = read_item();
The multiplication can wrap. If n * sizeof *p exceeds the range of size_t, the result silently wraps around to a small number, malloc happily returns a tiny block, and the loop then writes n items into it. The program writes far past the end of the allocation. Unsigned overflow is well-defined in C, which makes this worse: no UB, no warning, just a wrong size.
Safer options:
/* 1. let the allocator check it */
struct item *p = calloc(n, sizeof *p);
/* 2. check by hand */
if (n > SIZE_MAX / sizeof *p) return -1;
struct item *p = malloc(n * sizeof *p);
/* 3. reallocarray(NULL, n, sizeof *p) where available */
calloc is required to detect the overflow and fail. Also, validate n against what the file can possibly contain before allocating at all: a header that claims four billion items in a 2 KB file is lying.
The bug is old, boring, and still shows up in code written last week. As is tradition.