Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Mar 21, 2024

The spec says

If pos is greater than the number of WTF-16 code units in view, it is as if it were instead given as the code unit length. This transformation is the "WTF-16 position treatment".

(stringview_wtf16.slice view:stringview_wtf16 start:i32 end:i32)
  -> str:stringref

Return a substring of view, for the WTF-16 code units starting at offset start and continuing to but not including end. start and end receive the "WTF-16 position treatment", as for stringview_wtf16.encode.

My understanding is that that means if the end is larger than the size, it is shrunk to the size. That is,

end = min(end, actual size)

That appears to match what V8 does, thereby fixing a fuzz bug, and also matches what JS strings do. Before, we used to trap on out of bounds here.

@kripken kripken requested a review from tlively March 21, 2024 00:12
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

This spec has all sorts of surprises in it...

@kripken kripken merged commit b1535da into WebAssembly:main Mar 21, 2024
@kripken kripken deleted the string.slice.end branch March 21, 2024 17:07
@gkdn gkdn mentioned this pull request Aug 31, 2024
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