fix: fix memory bugs and last-char truncation in deHTMLxs XS#55
Merged
Conversation
doit() had three bugs: (1) overwriting the last character of input with '\0' before HTML stripping, silently losing one byte of content; (2) leaking the intermediate SV created by newSVpv — replaced with sv_setpv which sets the value directly; (3) using malloc/free instead of Perl's Newx/Safefree memory API. Also adds an empty-string guard to prevent buffer underflow when size==0, replaces deprecated Newz with Newxz in new(), and removes unnecessary input mutation in isit(). Golden test files regenerated to match corrected output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
CPAN Testers EvidenceI analyzed the CPAN Testers failure reports for v2.86 (API data). The results confirm this PR fixes the root cause of all 45 FAIL reports. Summary
Root Cause Chain
Why only html.4, html.5, html.8These three input files end with Why this PR fixes itWith truncation removed, the golden files end with proper 🤖 Analysis by Kōan |
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.
What
Fix three bugs in the deHTMLxs XS extension: memory leak, input truncation, and unsafe memory operations.
Why
doit()overwrote the last character of input with\0before HTML stripping — silently losing one byte of content on every call. It also leaked an intermediate SV vianewSVpv+sv_setsv(the temporary was never freed), and used Cmalloc/freeinstead of Perl'sNewx/Safefreememory API (bypassing Perl's memory debugging and tracking). Additionally,doit()had no guard against empty strings — calling it withsize==0would write toraw[-1](buffer underflow).How
*(raw + size - 1) = '\0'— Perl SVs fromSvPVare already null-terminated atraw[size], making this destructive overwrite unnecessary.newSVpv+sv_setsvwithsv_setpv, which sets the value directly without creating a temporary SV.malloc/freewithNewx/Safefree. Also replaced deprecatedNewzwithNewxzinnew().size == 0guard before buffer operations.sv_catpv(text, &mynull)hack that unnecessarily touched the input SV.Testing
All 182 tests pass. Golden
.deHTMLxsfiles regenerated — 5 files grew by exactly 1 byte each (the previously truncated character).🤖 Generated with Claude Code
Quality Report
Changes: 6 files changed, 15 insertions(+), 34 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline