Fix null pointer dereference in Matroska parser on file open failure (#2171)

create_file() returns the result of fopen() which can be NULL if the
file cannot be opened. matroska_loop() never checked this, passing
the NULL pointer into matroska_parse() where it is immediately used
in feof(), causing a crash.

Add a NULL check that calls fatal(EXIT_READ_ERROR, ...) on failure,
consistent with other file-open error handling in the codebase.
This commit is contained in:
Apoorv Darshan
2026-03-14 22:33:39 +05:30
committed by GitHub
parent af53968611
commit 538e39db67

View File

@@ -2053,6 +2053,12 @@ int matroska_loop(struct lib_ccx_ctx *ctx)
mkv_ctx->current_second = 0;
mkv_ctx->filename = ctx->inputfile[ctx->current_file];
mkv_ctx->file = create_file(ctx);
if (mkv_ctx->file == NULL)
{
char *fname = mkv_ctx->filename;
free(mkv_ctx);
fatal(EXIT_READ_ERROR, "Could not open MKV file: %s\n", fname);
}
mkv_ctx->sub_tracks = malloc(sizeof(struct matroska_sub_track **));
if (mkv_ctx->sub_tracks == NULL)
fatal(EXIT_NOT_ENOUGH_MEMORY, "In matroska_loop: Out of memory allocating sub_tracks.");