Reject negative ROM lengths in uvm32_load#12
Merged
ringtailsoftware merged 1 commit intoJul 16, 2026
Conversation
uvm32_load accepted negative int lengths and forwarded them to the size_t copy parameter. Reject them alongside oversized ROMs so invalid input follows the existing false return path. Constraint: Keep the public int signature and existing zero/exact-fit behavior Rejected: Change len to size_t | unnecessary API and ABI change Confidence: high Scope-risk: narrow Directive: Validate signed lengths before passing them to size_t APIs Tested: Hook boundary matrix on MinGW GCC 8 and WSL GCC 13; Unity badcode 2/2; stack-protection configuration; WSL ASan/UBSan; git diff --check Not-tested: Full Docker suite locally because the RISC-V cross compiler and Docker service were unavailable
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
Problem
uvm32_load() accepts len as an int, but currently checks only whether it exceeds UVM32_MEMORY_SIZE. A negative value therefore reaches UVM32_MEMCPY, whose length parameter is size_t, after an unintended signed-to-unsigned conversion.
Negative byte counts have no valid meaning for this API. Checking the lower bound before the copy keeps invalid input consistent with the existing oversized-ROM behavior without changing the public signature.
Testing
A non-copying UVM32_MEMCPY recording hook linked the real uvm32.c and exercised INT_MIN, -1, 0, 1, exact fit, and one byte over the limit.
On current main, INT_MIN and -1 both returned true and invoked the copy hook once. With this change they return false without invoking it; all non-negative boundary results remain unchanged.
Verified with:
Limitations
The full Docker suite was not available locally because this machine does not have the repository's RISC-V cross compiler and its Docker service is not running. The pull request CI will run that complete environment.