Skip to content

fix exploreState type guard to accept numeric state#891

Open
metsw24-max wants to merge 1 commit into
CodeIntelligenceTesting:mainfrom
metsw24-max:explorestate-number-guard
Open

fix exploreState type guard to accept numeric state#891
metsw24-max wants to merge 1 commit into
CodeIntelligenceTesting:mainfrom
metsw24-max:explorestate-number-guard

Conversation

@metsw24-max

Copy link
Copy Markdown

exploreState guards its input with typeof state !== "string", but state is the numeric value forwarded to tracePcIndir and on to the native __sanitizer_cov_trace_pc_indir_with_pc hook. Every documented call passes a number, so the guard always returns early and the hint is silently dropped, while a stray string would reach the native handler unchecked. Switch the check to typeof state !== "number", matching the signature and the string guards in guideTowardsEquality and guideTowardsContainment. Includes a regression test.

state is numeric and forwarded to tracePcIndir, but the guard checked for string and always returned early, dropping the hint.
@metsw24-max

Copy link
Copy Markdown
Author

gentle ping

@oetr

oetr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@metsw24-max Can you explain in detail how you found this issue and what your setup is?

@metsw24-max

Copy link
Copy Markdown
Author

How I found it

Reading through the guidance helpers in packages/fuzzer/trace.ts. exploreState sits right next to guideTowardsEquality and guideTowardsContainment, and those two guard their string params with typeof x !== "string". exploreState uses the same !== "string" check, but its state param is typed and documented as a number and gets forwarded to tracePcIndir. So the guard trips on every valid numeric call and the hint is dropped, while a stray string would slip past into the native handler. It reads like a copy-paste from the string helpers rather than intended behaviour.

Setup

Nothing elaborate, this came from reading the source rather than a fuzzing run, since a silently dropped hint won't surface as a crash. To confirm, I mocked ./addon in trace.test.ts and checked that tracer.exploreState(state, id) actually reaches tracePcIndir; with the old !== "string" guard it never does. Just the repo's normal node/jest setup, running the fuzzer package tests.

Happy to move the test if you'd rather it lived elsewhere.

@oetr

oetr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@metsw24-max Can you check if mocking all of these is strictly necessary? If not, please remove:

		traceUnequalStrings: jest.fn(),
		traceStringContainment: jest.fn(),
		traceIntegerCompare: jest.fn(),

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