fix: discard generated segment output that has no probeable duration#181
Open
seonghobae wants to merge 1 commit into
Open
fix: discard generated segment output that has no probeable duration#181seonghobae wants to merge 1 commit into
seonghobae wants to merge 1 commit into
Conversation
_execute_segment_conversion probed the freshly generated output for its duration without guarding against probe_media raising MediaShrinkerError. ffmpeg can exit 0 yet produce a truncated/empty output whose duration is missing or zero; _parse_probe_payload raises for such files. The exception propagated out of the conversion, so the invalid output file was orphaned on disk (and re-probed/re-raised on every subsequent run) instead of being discarded like the too_large/too_long/duration_mismatch cases. Wrap the probe in a MediaShrinkerError guard that discards the invalid output via _discard_invalid_generated_output and returns a graceful duration_mismatch failure with output_path=None. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CJRVbDrp1vGYkJgNHMGPpG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_execute_segment_conversionvalidates a freshly generated segment output by probing its duration:probe_media(via_parse_probe_payload) raisesMediaShrinkerErrorwhen the output has no usable/zero duration or no audio stream. ffmpeg can exit0yet still produce a truncated/empty output (e.g. a degenerate last segment, or a-sspast the end). In that case the exception propagated straight out of the conversion:too_large/too_long/duration_mismatchcases, which all discard the file._find_valid_existing_outputre-probes that leftover file, raises again, and the corrupt output poisons the source permanently (it is never cleaned up).This matches two of the audited failure modes: a duration parse that mishandles missing/zero, and discard logic that leaves an invalid file.
Fix
Guard the probe with a
MediaShrinkerErrorhandler that discards the invalid output via the existing_discard_invalid_generated_outputhelper and returns a gracefulduration_mismatchresult (output_path=None,duration_seconds=None). Minimal, localized to the duration-validation region.Test
Added
test_convert_segment_discards_output_that_has_no_probeable_duration, which fakes an ffmpeg that writes a file the probe cannot read a duration for. It fails on the pre-fix code (raisesMediaShrinkerError, file left on disk) and passes after the fix (statusduration_mismatch, file removed).Gates
coverageonmedia_shrinker.py: 100%interrogate: 100%os.listxattrerrors (baseline) — no new failures.🤖 Generated with Claude Code