Skip to content

Fix off-by-one in assert_no_overlap boundary check#12678

Open
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/assert-no-overlap-off-by-one
Open

Fix off-by-one in assert_no_overlap boundary check#12678
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/assert-no-overlap-off-by-one

Conversation

@sumleo
Copy link

@sumleo sumleo commented Feb 26, 2026

Summary

  • Fixed boundary comparison in assert_no_overlap using <= instead of <
  • Adjacent non-overlapping memory regions were incorrectly triggering the overlap assertion
  • Added 8 comprehensive tests for boundary conditions

Details

The assert_no_overlap function in component model string transcoding used strict
less-than (<) to compare region boundaries. When two memory regions are adjacent
(e.g., region A ends at address 100, region B starts at address 100), the strict
comparison incorrectly identified them as overlapping, causing a panic.

The fix changes both boundary checks from < to <=, correctly allowing adjacent
non-overlapping regions while still detecting actual overlaps.

Test plan

  • Added unit tests for separate, adjacent, and overlapping regions
  • Added tests for mixed types (u8/u16) and empty slices
  • Verified overlap detection still works (should_panic tests)
  • All existing tests pass

The assert_no_overlap function used strict less-than (<) comparisons
to check if two memory regions overlap. This incorrectly rejected
adjacent non-overlapping regions where one region's end address
equals another region's start address. Changed to less-than-or-equal
(<=) to correctly allow adjacent regions.

Added comprehensive tests covering separate regions, adjacent regions,
mixed types, overlap detection, and edge cases.
@sumleo sumleo requested a review from a team as a code owner February 26, 2026 01:42
@sumleo sumleo requested review from fitzgen and removed request for a team February 26, 2026 01:42
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Feb 26, 2026
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that you encountered in practice? This looks like it was LLM-discovered and LLM-authored otherwise, and I'm not aware of a way for this to actually ever be a problem in practice. This seems reasonable to me to fix but I would say that the tests can be dropped here given the non-load-bearing nature of this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants