Closed aapoalas closed 1 month ago
Closes #1531?
Oh, yes
LGTM provided that the answer to #1532 (comment) is "yes"
I couldn't give a full "yes" so I fixed the code to check for length being zero. If length is zero, then the pointer could also theoretically be null.
A subtle unsoundness / undefined behaviour made its way into the fairly recently added
ExternalOneByteStringResource
object: Theas_str
API is not sound as the data inside may be be Latin-1, not ASCII.As the API was not used anywhere in deno or deno_core, I opted to simply remove it and replace it with an
as_bytes
API. I also modified the test to showcase the Latin-1 string case and added copious notes and explanations around the code to make sure this doesn't accidentally happen again. The likely reason why the API originally slipped in is because theOneByteConst
has this API where it is safe because theOneByteConst
creation checks the data for ASCII-ness.I also tried to add an API to extract an
Option<&'static OneByteConst>
from an&ExternalOneByteStringResource
but run into https://github.com/rust-lang/rust/issues/119618 ie. OneByteConst is actually duplicating the vtables... which is not great.Closes #1531