Repository navigation
Fix mapped input dangling - #429
Merged
Merged
Conversation
ucl_parser_add_fd_full and ucl_parser_add_file_full mmap the input, parse it, then munmap it. Two things still point into the mapping afterwards. Zero-copy objects: with UCL_PARSER_ZEROCOPY, keys and string values are pointers into the input, so after a successful ucl_parser_add_fd a lookup reads unmapped memory. The flag documents zero-copy 'if possible', and for a file it never is, because the library releases the buffer itself. The chunk: it stays in parser->chunks with pos/end into the mapping, so after a parse error ucl_parser_chunk_peek and ucl_parser_chunk_skip dereference it. Add a helper used by both: parse with UCL_PARSER_ZEROCOPY temporarily cleared, unmap, and clear begin/pos/end/remain of the chunk that referred to it - chunk_peek and chunk_skip already treat a NULL pos as no data. Zero-copy for ucl_parser_add_chunk*, where the caller owns the memory, is unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W3aXdPKAnVwjiNtZstnmPj
vstakhov
approved these changes
Oct 7, 2026
vstakhov
left a comment
Owner
There was a problem hiding this comment.
LGTM. Reproduced both cases from the issue on master under ASan: the zerocopy lookup after ucl_parser_add_fd(), and chunk peek/skip after a failed parse. Both are clean on this branch.
Non-blocking follow-up: .include (ucl_include_file_single) has the same pattern. It mmaps, parses with the caller's UCL_PARSER_ZEROCOPY, then munmaps. So zerocopy + .include from caller-owned input still leaves keys dangling, and a failed include leaves a chunk pointing into the unmapped file.
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.
Fix #428