mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-02-03 21:23:48 +00:00
[PR #2004] [MERGED] fix(matroska): Prevent infinite loop on truncated MKV files #2806
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/CCExtractor/ccextractor/pull/2004
Author: @cfsmp3
Created: 1/10/2026
Status: ✅ Merged
Merged: 1/10/2026
Merged by: @cfsmp3
Base:
master← Head:fix/matroska-eof-infinite-loop📝 Commits (1)
067045cfix(matroska): Prevent infinite loop on truncated MKV files📊 Changes
1 file changed (+17 additions, -0 deletions)
View changed files
📝
src/lib_ccx/matroska.c(+17 -0)📄 Description
Summary
mkv_read_byte()call in all Matroska parsing loopsProblem
When parsing truncated MKV files, the Matroska parser would enter an infinite loop printing millions of "Unknown element 0xffffffff" warnings. This happened because:
fgetc()returns -1 which becomes 0xFF when cast to UBYTEFSEEKpast EOF clears the EOF flag without error(pos + len > get_current_byte)never becomes false because the recorded segment length is larger than the truncated fileSolution
Add
feof()checks immediately after eachmkv_read_byte()call in all 8 parsing loops. This detects EOF after the failed read and breaks out of the loop cleanly.Test plan
ticket1398-orig.mkv(10MB truncated, 3hr duration) - previously hung, now completes instantlyazumi.mkv(33MB truncated, 2hr duration) - previously hung, now completes in ~36 seconds with correct subtitle extraction🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.