encoding icon indicating copy to clipboard operation
encoding copied to clipboard

Make encodeInto() throw when given a detached buffer

Open annevk opened this issue 1 year ago • 7 comments
trafficstars

In https://github.com/whatwg/webidl/issues/1385 we discovered some specification UB. However, that also raised the question as to whether this method should perhaps be throwing an exception when given a detached buffer.

I tend to think it should and hopefully there's no callers relying on it not throwing as it's still early days?

cc @hsivonen @inexorabletash @youennf

annevk avatar Jan 24 '24 14:01 annevk

cc @ricea

inexorabletash avatar Jan 24 '24 20:01 inexorabletash

Chrome accidentally does nothing successfully.

I think we should throw. My guess is that no-one is intentionally using the current behaviour.

ricea avatar Jan 25 '24 04:01 ricea

Is the goal to add a one-off check to Encoding, or to throw at the Web IDL layer? The latter would be kind of nice, but perhaps scarier.

domenic avatar Jan 25 '24 04:01 domenic

Throwing at the IDL layer would change the exception for everything calling into StructuredSerializeWithTransfer at least. Not sure that's really possible. My idea was to add one-off checks and also to assert that the buffer is not detached in various IDL algorithms so callers are "forced" to deal with it.

annevk avatar Jan 25 '24 06:01 annevk

This also applies to TextDecoder's decode() and looking at https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy the handling of detached buffers is pretty intentional at least for that and APIs like it.

I suspect it's all aligned with the original non-throwy view APIs. This makes me a bit more worried about introducing a throw here and there as it seems unlikely we will be able to be consistent.

Thoughts?

annevk avatar Feb 01 '24 16:02 annevk