Repository navigation
encoding: switch to explicit dom string replacement in text encoder - #48183
Conversation
Signed-off-by: gterzian <[email protected]>
|
Need to check whether this is too much of a simplification and breaks behavior. |
|
🔨 Triggering try run (#35345835338) for Linux (WPT) |
Signed-off-by: gterzian <[email protected]>
|
Test results for linux-wpt from try job (#35345835338): Flaky unexpected result (23)
Stable unexpected results that are known to be intermittent (18)
Stable unexpected results (7)
|
|
|
Signed-off-by: gterzian <[email protected]>
|
I'm making some more changes to this one; turns out our DOMString assumes utf 8 which appeared ok until encoding was implemented, but actually is a problem, so the simplication does not work, although there is some clean-ups I can do and I can also move this into the str module in script_bindings and note that we really should fold this into a spec compliant implementation of dom string later. For reference, this seems refuted by the needs of encodings: https://github.com/gterzian/servo/blob/407402e9f5a97219fd16051cbd4a047e00c3be4a/components/script_bindings/domstring.rs#L277 |
…ings/str Signed-off-by: gterzian <[email protected]>
|
🔨 Triggering try run (#35577579632) for Linux (WPT) |
|
Test results for linux-wpt from try job (#35577579632): Flaky unexpected result (31)
Stable unexpected results that are known to be intermittent (13)
Stable unexpected results (1)
|
|
|
|
/fetch/metadata/generated/css-images.https.sub.tentative.html seems unrelated to the changes in this pr. |
|
🔨 Triggering try run (#35586960160) for Linux (WPT) |
|
Test results for linux-wpt from try job (#35586960160): Flaky unexpected result (29)
Stable unexpected results that are known to be intermittent (13)
Stable unexpected results (2)
|
|
|
|
🔨 Triggering try run (#35595318225) for Linux (WPT) |
|
Test results for linux-wpt from try job (#35595318225): Flaky unexpected result (29)
Stable unexpected results that are known to be intermittent (17)
Stable unexpected results (1)
|
|
|
Signed-off-by: gterzian <[email protected]>
| // but the returned slice is tied to the handle to the data underlying the string, | ||
| // so the "The memory referenced by the returned slice must not be mutated" invariant | ||
| // of `from_raw_parts` should be maintained. | ||
| std::slice::from_raw_parts(data, len) |
There was a problem hiding this comment.
I am spending some time reading the safety code these days, and I think returning slice can outlive the rooted js string 🤔 , because jsstr is rooted only inside this function, what happnes when the function returns and that root disappears, while the caller still holds the slice ?
There was a problem hiding this comment.
so as documented above, I was thinking what matters is not the js string, which I think is just a view into data, but the actual data which is kept alive by the handle passed to this function; meaning the js string may not live as long as the slice, but the handle will and that is where the data is coming from at the end of the day; but I'm not sure so let me know what you think pls.
There was a problem hiding this comment.
Ok I have now I think made it so we don't have to guess and the js string is kept alive in any case; thanks for pointing it out.
There was a problem hiding this comment.
This might be related but why is this sound? Even if the data is kept alive by the handle, the reference maybe_ill_formed_code_units points to might get moved by the GC and then we point to arbitrary memory?
There was a problem hiding this comment.
I am asking whether this can actually occur in https://matrix.to/#/!CZEbuMfGYVdQMIBKeP:mozilla.org/$ni6DzdXKpIpuLsSCTQGMb9mVjrd9jv92mfyOgUu4XO8?via=mozilla.org&via=matrix.org&via=igalia.com
Answer: yes.
There was a problem hiding this comment.
What to do? Clone data into a vec?
There was a problem hiding this comment.
I am not sure if I understand this work because it feels like it should all be encapsulated in DOMString. But GetTwoByteStringCharsAndLength looks cheap to me (after lineraization) (https://searchfox.org/firefox-main/source/js/src/jsapi.cpp#3456). So can we just keep the *JSString and get the code units on demand?
There was a problem hiding this comment.
So I added a copy for now, and I think it is worth being precise about what the problem is in this specific case. In general, yes the gc could move the string and then the slice would point to garbage, but in this specific code, could it be a problem?
In the code in this PR, ignoring the last commit that introduces a copy, I am not sure if there is in fact a GC hazard because the slice is passed only to encode, which does not call into js.
So can we just keep the *JSString and get the code units on demand?
Yes and isn't that what the code was doing already?
Looking at /js/public/StableStringChars.h, it seems they essentially root the string, and then only sometimes do a copy.
so it seems there are two things we can do:
- Add some markers that "prove" that
encodecannot do a GC, and then I think we can conclude that passing the slice, while rooting the string, is safe. - Copy the data just to be on the safe side (done with latest commit).
- introduce a re-usable abstraction like
StableStringChars.h, probably good for a follow up.
Am I missing something?
Signed-off-by: gterzian <[email protected]>
| // Note: rooting the jsstring only for the scope of this function call, | ||
| // but the returned slice is tied to the handle to the data underlying the string, | ||
| // so the "The memory referenced by the returned slice must not be mutated" invariant | ||
| // of `from_raw_parts` should be maintained. |
There was a problem hiding this comment.
I need to update this or just remove the doc actually since now nothing weird is happening
Signed-off-by: gterzian <[email protected]>
Signed-off-by: gterzian <[email protected]>
…ervo#48183) Move js to dom string conversion to a safe ad hoc function mirroring DOMstring but supporting the needs of dom/encodings; remove unnecessary conversion to a primitive. Document DOMstring::from_js_string and root the string pointer used in it. Testing: no change in behavior. Fixes: Part of servo#30862 --------- Signed-off-by: gterzian <[email protected]>
…ervo#48183) Move js to dom string conversion to a safe ad hoc function mirroring DOMstring but supporting the needs of dom/encodings; remove unnecessary conversion to a primitive. Document DOMstring::from_js_string and root the string pointer used in it. Testing: no change in behavior. Fixes: Part of servo#30862 --------- Signed-off-by: gterzian <[email protected]>
Move js to dom string conversion to a safe ad hoc function mirroring DOMstring but supporting the needs of dom/encodings; remove unnecessary conversion to a primitive.
Document DOMstring::from_js_string and root the string pointer used in it.
Testing: no change in behavior.
Fixes: Part of #30862