stream: disallow writing string chunk with 'buffer' encoding#63062
stream: disallow writing string chunk with 'buffer' encoding#63062Renegade334 wants to merge 2 commits into
Conversation
|
Review requested:
|
There was a problem hiding this comment.
This was a test for the behaviour reported in #12152, where calling .write('string', 'buffer') on a StreamBase-backed stream would crash the process. I don't believe there's any way to hit this if this change lands, but not confidently enough to revert back to a CHECK (cf. #12753) without a second opinion – maybe Team Stream has an insight?
(cc @addaleax)
There was a problem hiding this comment.
I'm fairly confident that this can't now be hit (
Lines 67 to 73 in 843dc5f
| const w = new Writable({ | ||
| autoDestroy, | ||
| _write() {} | ||
| write() {} |
There was a problem hiding this comment.
These tests were using the wrong constructor option name for setting the _write implementation. It doesn't matter if the error tests fail as expected, but it does make the assertion message less clear if an error test doesn't fail, as it instead complains about a missing _write implementation rather than reporting the missing expected error.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63062 +/- ##
=======================================
Coverage 90.05% 90.06%
=======================================
Files 714 714
Lines 225247 225248 +1
Branches 42578 42580 +2
=======================================
+ Hits 202842 202860 +18
+ Misses 14181 14180 -1
+ Partials 8224 8208 -16
🚀 New features to boost your workflow:
|
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
0a4cd53 to
b420c0f
Compare
In non-object mode,
Writable.prototype.write()validates the encoding as either'buffer'or a valid string encoding.Under default conditions, passing the encoding
'buffer'in combination with a string chunk results indirectly in an ERR_UNKNOWN_ENCODING error, because those are passed toBuffer.from()which considers the'buffer'encoding to be invalid.However, when decodeStrings is disabled, this indirect validation does not occur, and the string chunk is sent to the
write()implementation with the encoding'buffer', which is obviously nonsense.semver... something?
Refs: #33075