Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 09cacd7

Browse filesBrowse files
jasnelltargos
authored andcommitted
src: fix setting Converter sub char length
Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: #38330 PR-URL: #38331 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 3649ec5 commit 09cacd7
Copy full SHA for 09cacd7

File tree

Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed
Open diff view settings
Collapse file

‎src/node_i18n.cc‎

Copy file name to clipboardExpand all lines: src/node_i18n.cc
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,13 @@ MaybeLocal<Object> Transcode(Environment* env,
148148
*status = U_ZERO_ERROR;
149149
MaybeLocal<Object> ret;
150150
MaybeStackBuffer<char> result;
151-
Converter to(toEncoding, "?");
151+
Converter to(toEncoding);
152152
Converter from(fromEncoding);
153+
154+
size_t sublen = ucnv_getMinCharSize(to.conv());
155+
std::string sub(sublen, '?');
156+
to.set_subst_chars(sub.c_str());
157+
153158
const uint32_t limit = source_length * to.max_char_size();
154159
result.AllocateSufficientStorage(limit);
155160
char* target = *result;
@@ -190,7 +195,12 @@ MaybeLocal<Object> TranscodeFromUcs2(Environment* env,
190195
*status = U_ZERO_ERROR;
191196
MaybeStackBuffer<UChar> sourcebuf;
192197
MaybeLocal<Object> ret;
193-
Converter to(toEncoding, "?");
198+
Converter to(toEncoding);
199+
200+
size_t sublen = ucnv_getMinCharSize(to.conv());
201+
std::string sub(sublen, '?');
202+
to.set_subst_chars(sub.c_str());
203+
194204
const size_t length_in_chars = source_length / sizeof(UChar);
195205
CopySourceBuffer(&sourcebuf, source, source_length, length_in_chars);
196206
MaybeStackBuffer<char> destbuf(length_in_chars);
Collapse file

‎test/parallel/test-icu-transcode.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-icu-transcode.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ assert.deepStrictEqual(
8383
const dest = buffer.transcode(new Uint8Array(), 'utf8', 'latin1');
8484
assert.strictEqual(dest.length, 0);
8585
}
86+
87+
// Test that it doesn't crash
88+
{
89+
buffer.transcode(new buffer.SlowBuffer(1), 'utf16le', 'ucs2');
90+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.