{{ message }}
Repository navigation
Fix mstrGetFlag out-of-bounds read without metadata - #16023
Open
Huang-404-Q wants to merge 1 commit into
Open
Huang-404-Q wants to merge 1 commit into
Huang-404-Q wants to merge 1 commit into
Conversation
mstrGetFlag() called mstrFlagsRef() unconditionally, which points before the allocation when no metadata is attached. Reading the flags word then reads 2 bytes to the left of the allocation (ASAN heap-buffer-overflow), and a caller that trusts a nonzero result can reach an out-of-range metadata pointer. Check mstrIsMetaAttached() first, as the header comment already tells callers to do. Adds an mstrTest case for a metadata-less string.
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.

Summary
mstrGetFlag()calledmstrFlagsRef()unconditionally, which points before the allocation when no metadata is attached. Reading the flags word then reads 2 bytes to the left of the allocation (ASAN heap-buffer-overflow), and a caller that trusts a nonzero result can reach an out-of-range metadata pointer.Check
mstrIsMetaAttached()first, as the header comment already tells callers to do.Test
Adds an
mstrTestcase for a metadata-less string.AI assistance
Tool(s) used: Claude Code
How you used it: the assistant read the code, wrote the fix and the test, and ran the built-in test. A human reviewed the diff and takes responsibility for the change.
Note
Low Risk
Small, localized safety fix in an inline helper plus a unit test; behavior for metadata-backed strings is unchanged.
Overview
Fixes
mstrGetFlagso it no longer reads flag bits when anmstrhas no metadata attached. The inline helper now returns 0 unlessmstrIsMetaAttached(s)is true, matching the documented expectation that callers should verify metadata before using flag/metadata APIs.Previously it always called
mstrFlagsRef()and dereferenced the flags word; without metadata that address sits before the allocation, which triggers ASAN heap-buffer-overflow and could yield bogus nonzero flags.Adds an
mstrTestcase that builds a plainmstrNewstring and assertsmstrGetFlag(s, 0) == 0.Reviewed by Cursor Bugbot for commit e61d1a8. Bugbot is set up for automated code reviews on this repo. Configure here.