From 395f9b32139296933681995bfc0361dc09fc583e Mon Sep 17 00:00:00 2001 From: Dhanush Date: Sun, 5 Apr 2026 02:58:48 +0530 Subject: [PATCH] fix: MKV subtitle track .(null) extension for KATE and unknown codec IDs (#2250) * fix: MKV subtitle track .(null) extension for KATE and unknown codec IDs The matroska_track_text_subtitle_id_extensions array had 7 entries for an 8-value enum, leaving MATROSKA_TRACK_SUBTITLE_CODEC_ID_KATE (index 7) out of bounds. On most platforms this read NULL, which then caused strlen(NULL) UB and snprintf to emit .(null) in the output filename. Two fixes: - Add "kate" at index 7 in the extensions array so KATE tracks produce correct .kate output filenames - Add a NULL guard in generate_filename_from_track() so any future unknown codec ID safely falls back to .bin instead of crashing or producing .(null) Fixes #972 * fix: MKV subtitle track .(null) extension for KATE and unknown codec IDs The matroska_track_text_subtitle_id_extensions array had 7 entries for an 8-value enum, leaving MATROSKA_TRACK_SUBTITLE_CODEC_ID_KATE (index 7) out of bounds. On most platforms this read NULL, which then caused strlen(NULL) UB and snprintf to emit .(null) in the output filename. Two fixes: - Add "kate" at index 7 in the extensions array so KATE tracks produce correct .kate output filenames - Add a NULL guard in generate_filename_from_track() so any future unknown codec ID safely falls back to .bin instead of crashing or producing .(null) Fixes #972 * fix: MKV subtitle track .(null) extension for KATE and unknown codec IDs The matroska_track_text_subtitle_id_extensions array had 7 entries for an 8-value enum, leaving MATROSKA_TRACK_SUBTITLE_CODEC_ID_KATE (index 7) out of bounds. On most platforms this read NULL, which then caused strlen(NULL) UB and snprintf to emit .(null) in the output filename. Two fixes: - Add "kate" at index 7 in the extensions array so KATE tracks produce correct .kate output filenames - Add a NULL guard in generate_filename_from_track() so any future unknown codec ID safely falls back to .bin instead of crashing or producing .(null) Fixes #972 --------- Co-authored-by: Dhanush Varma --- src/lib_ccx/matroska.c | 2 ++ src/lib_ccx/matroska.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib_ccx/matroska.c b/src/lib_ccx/matroska.c index 3b3d8a81..3da24e99 100644 --- a/src/lib_ccx/matroska.c +++ b/src/lib_ccx/matroska.c @@ -1333,6 +1333,8 @@ char *generate_filename_from_track(struct matroska_ctx *mkv_ctx, struct matroska { const char *basename = get_basename(mkv_ctx->filename); const char *extension = matroska_track_text_subtitle_id_extensions[track->codec_id]; + if (extension == NULL) + extension = "bin"; /* Prefer the BCP-47 IETF tag (e.g. "zh-Hant") over the legacy * ISO-639-2 code (e.g. "chi") when one is available. */ const char *lang_tag = track->lang_ietf ? track->lang_ietf : track->lang; diff --git a/src/lib_ccx/matroska.h b/src/lib_ccx/matroska.h index d5ebcd64..8493cb3b 100644 --- a/src/lib_ccx/matroska.h +++ b/src/lib_ccx/matroska.h @@ -179,7 +179,7 @@ char *matroska_track_text_subtitle_id_strings[] = { char *matroska_track_text_subtitle_id_extensions[] = { "srt", "ssa", "ass", "usf", "vtt", "bmp", - "idx", NULL // Unknown + "idx", "kate", NULL // Unknown/sentinel }; char *avc_codec_id = "V_MPEG4/ISO/AVC";