Skip to content

fix: possible leak on base64 decode failure#338

Merged
rockorager merged 1 commit into
rockorager:mainfrom
WilliamHCarter:fix-parser-errdefer
May 15, 2026
Merged

fix: possible leak on base64 decode failure#338
rockorager merged 1 commit into
rockorager:mainfrom
WilliamHCarter:fix-parser-errdefer

Conversation

@WilliamHCarter
Copy link
Copy Markdown
Contributor

decoder.decode can fail on malformed base64 input after text has already been allocated, this adds an errdefer so the temporary allocation is released if decode fails before ownership transfer.

for repro I used a simple test to confirm the leak, I didn't add this to the pr so as not to bloat the test set:

test "parse: osc52 paste with malformed base64 does not leak" {
const alloc = testing.allocator_instance.allocator();
// "!!!!" is not valid base64; decode() will return error.InvalidCharacter
const input = "\x1b]52;c;!!!!\x1b\";
var parser: Parser = .{};
try testing.expectError(error.InvalidCharacter, parser.parse(input, alloc));
}

@rockorager rockorager merged commit ba5be67 into rockorager:main May 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants