mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
string_decoder: fix crash when calling __proto__.write()
This makes the function throw an exception from JS instead of crashing. Fixes: https://github.com/nodejs/node/issues/41949 Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: https://github.com/nodejs/node/pull/42062 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com>
This commit is contained in:
1 parent
b89f4d5c17
commit
3492a0eb1e
2 files changed
+11
No files matched your search
@@ -43,6 +43,7 @@ const {
|
||||
const internalUtil = require('internal/util');
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_THIS,
|
||||
ERR_UNKNOWN_ENCODING
|
||||
} = require('internal/errors').codes;
|
||||
const isEncoding = Buffer[internalUtil.kIsEncodingSymbol];
|
||||
@@ -101,6 +102,9 @@ StringDecoder.prototype.write = function write(buf) {
|
||||
throw new ERR_INVALID_ARG_TYPE('buf',
|
||||
['Buffer', 'TypedArray', 'DataView'],
|
||||
buf);
|
||||
if (!this[kNativeDecoder]) {
|
||||
throw new ERR_INVALID_THIS('StringDecoder');
|
||||
}
|
||||
return decode(this[kNativeDecoder], buf);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user