GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — string_decoder: fix crash when calling __proto__.write() · styfle/node@24fc302

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • string_decoder.js
  • test/parallel
    • test-string-decoder.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/string_decoder.js‎

Copy file name to clipboardExpand all lines: lib/string_decoder.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const {
4343
const internalUtil = require('internal/util');
4444
const {
4545
ERR_INVALID_ARG_TYPE,
46+
ERR_INVALID_THIS,
4647
ERR_UNKNOWN_ENCODING
4748
} = require('internal/errors').codes;
4849
const isEncoding = Buffer[internalUtil.kIsEncodingSymbol];
@@ -101,6 +102,9 @@ StringDecoder.prototype.write = function write(buf) {
101102
throw new ERR_INVALID_ARG_TYPE('buf',
102103
['Buffer', 'TypedArray', 'DataView'],
103104
buf);
105+
if (!this[kNativeDecoder]) {
106+
throw new ERR_INVALID_THIS('StringDecoder');
107+
}
104108
return decode(this[kNativeDecoder], buf);
105109
};
106110

Collapse file

‎test/parallel/test-string-decoder.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-string-decoder.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ if (common.enoughTestMem) {
210210
);
211211
}
212212

213+
assert.throws(
214+
() => new StringDecoder('utf8').__proto__.write(Buffer.from('abc')), // eslint-disable-line no-proto
215+
{
216+
code: 'ERR_INVALID_THIS',
217+
}
218+
);
219+
213220
// Test verifies that StringDecoder will correctly decode the given input
214221
// buffer with the given encoding to the expected output. It will attempt all
215222
// possible ways to write() the input buffer, see writeSequences(). The

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.