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 <your@email.com>
This commit is contained in:
Dhanush
2026-04-05 02:58:48 +05:30
committed by GitHub
parent 65df24e6bc
commit 395f9b3213
2 changed files with 3 additions and 1 deletions

View File

@@ -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 *basename = get_basename(mkv_ctx->filename);
const char *extension = matroska_track_text_subtitle_id_extensions[track->codec_id]; 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 /* Prefer the BCP-47 IETF tag (e.g. "zh-Hant") over the legacy
* ISO-639-2 code (e.g. "chi") when one is available. */ * ISO-639-2 code (e.g. "chi") when one is available. */
const char *lang_tag = track->lang_ietf ? track->lang_ietf : track->lang; const char *lang_tag = track->lang_ietf ? track->lang_ietf : track->lang;

View File

@@ -179,7 +179,7 @@ char *matroska_track_text_subtitle_id_strings[] = {
char *matroska_track_text_subtitle_id_extensions[] = { char *matroska_track_text_subtitle_id_extensions[] = {
"srt", "ssa", "ass", "srt", "ssa", "ass",
"usf", "vtt", "bmp", "usf", "vtt", "bmp",
"idx", NULL // Unknown "idx", "kate", NULL // Unknown/sentinel
}; };
char *avc_codec_id = "V_MPEG4/ISO/AVC"; char *avc_codec_id = "V_MPEG4/ISO/AVC";