Repository navigation
Conversation
luaL_fuzzed_data_provider() passes the pointer returned by
luaL_checklstring() straight to FuzzedDataProvider, which reads those
bytes on every consume call for the whole lifetime of the userdata. The
Lua string behind that pointer is anchored only while the constructor
runs: afterwards neither the stack nor the userdata references it, so an
input string with no other reference is collected and every later
consume call reads freed memory.
The form documented in docs/api.md is exactly that case:
fdp = luzer.FuzzedDataProvider(string.rep("A", 10^9))
fdp:consume_boolean()
Allocate the input bytes together with the userdata and point the
provider at that copy, so the data lives exactly as long as the provider
does. Anchoring the string instead would need a per-version uservalue
API (lua_setfenv(), lua_setuservalue(), lua_setiuservalue()), while the
copy works on every supported Lua.
Owner
|
Thanks for the patch! I'll review. |
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.
Repro:
luzer.FuzzedDataProvider(string.rep("A", 4096)), the form used in docs/api.md, then any consume call once the collector has run.Cause: the provider holds a pointer to the Lua string bytes, but the string is anchored only while the constructor runs, so an input with no other reference is collected while the provider is still in use.
Fix: keep the bytes in the userdata, whose lifetime is the provider's.
ASAN, Lua 5.4:
An explicit
collectgarbage()is not needed, the incremental collector gets there on its own. Without a sanitizer the read is silent: the freed buffer is reused and the provider returns the new occupant's bytes instead of the input. The check added totest_unit.luafails that way on master and passes with the patch.