fix: memory leaks and invalid CSS in WebVTT encoder#2164
fix: memory leaks and invalid CSS in WebVTT encoder#2164Varadraj75 wants to merge 2 commits intoCCExtractor:masterfrom
Conversation
- Remove 6 unnecessary strdup() calls on string literals in write_cc_buffer_as_webvtt() — literals are passed directly to write_wrapped() which takes void*, no heap allocation needed. This runs in a per-character inner loop and leaked on every styled subtitle in a broadcast. - Fix invalid CSS: rgba(0, 256, 0, 0.5) -> rgba(0, 255, 0, 0.5) CSS color channels are 0-255; 256 is out of range. - Fix missing free(unescaped) on write-error path in write_stringz_as_webvtt() — matched the existing pattern on the adjacent error path which correctly freed both el and unescaped. Fixes CCExtractor#2154
There was a problem hiding this comment.
Pull request overview
Fixes multiple correctness and memory-safety issues in the WebVTT encoder path (src/lib_ccx/ccx_encoders_webvtt.c) reported in #2154, improving long-running stability and standards compliance for generated WebVTT/CSS output.
Changes:
- Replace unnecessary
strdup()usage in the WebVTT styling write loop to eliminate repeated per-caption memory leaks. - Fix invalid inline CSS color channel value (
rgba(0, 256, 0, 0.5)→rgba(0, 255, 0, 0.5)). - Ensure
unescapedis freed on theencoded_crlfwrite-error path inwrite_stringz_as_webvtt().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/lib_ccx/ccx_encoders_webvtt.c |
Removes inner-loop leaks, corrects CSS output, and fixes an error-path leak in WebVTT writing. |
docs/CHANGES.TXT |
Adds a changelog entry describing the WebVTT fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit f377be9...:
Congratulations: Merging this PR would fix the following tests:
All tests passed completely. Check the result page for more info. |
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit f377be9...:
Your PR breaks these cases:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
|
The Windows CI failures are pre-existing and unrelated to this PR. All failing tests show "Last passed: Never" in the CI summary, confirming Linux CI passes all 237 tests cleanly. This PR only modifies |
In raising this pull request, I confirm the following (please check boxes):
My familiarity with the project is as follows (check one):
Summary
Three bugs fixed in
src/lib_ccx/ccx_encoders_webvtt.c, reported in #2154.Fix 1 — Remove 6 unnecessary
strdup()memory leaksInside
write_cc_buffer_as_webvtt(), string literals"<i>","<u>","<c.","</c>","</u>","</i>"were heap-allocated withstrdup()and passed towrite_wrapped()but never freed. Sincewrite_wrapped()takes avoid*anddoesn't require heap memory, the
strdup()calls were completely unnecessary.This ran in a per-character, per-row, per-subtitle inner loop — leaking thousands
of tiny allocations per styled broadcast hour.
Fix 2 — Invalid CSS
rgba(0, 256, 0, 0.5)→rgba(0, 255, 0, 0.5)CSS color channels are 0–255. The value
256is out of range and generatestechnically invalid CSS that strict parsers and validators reject.
Fix 3 — Missing
free(unescaped)on write-error pathIn
write_stringz_as_webvtt(), the error path after a failedencoded_crlfwrite freed
elbut notunescaped, unlike the adjacent error path above itwhich correctly freed both. Added the missing
free(unescaped)beforereturn -1.Testing
All existing CI tests pass. Built and verified locally on macOS.
Fixes #2154