| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d5e1b82 commit d2b9e7c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | #include "env-inl.h" | |
| 5 | 5 | #include "node_buffer.h" | |
| 6 | + #include "node_errors.h" | ||
| 6 | 7 | #include "node_external_reference.h" | |
| 7 | 8 | #include "string_bytes.h" | |
| 8 | 9 | #include "util.h" | |
@@ -30,11 +31,17 @@ MaybeLocal<String> MakeString(Isolate* isolate, | |||
| 30 | 31 | Local<Value> error; | |
| 31 | 32 | MaybeLocal<Value> ret; | |
| 32 | 33 | if (encoding == UTF8) { | |
| 33 | - return String::NewFromUtf8( | ||
| 34 | + MaybeLocal<String> utf8_string = String::NewFromUtf8( | ||
| 34 | 35 | isolate, | |
| 35 | 36 | data, | |
| 36 | 37 | v8::NewStringType::kNormal, | |
| 37 | 38 | length); | |
| 39 | + if (utf8_string.IsEmpty()) { | ||
| 40 | + isolate->ThrowException(node::ERR_STRING_TOO_LONG(isolate)); | ||
| 41 | + return MaybeLocal<String>(); | ||
| 42 | + } else { | ||
| 43 | + return utf8_string; | ||
| 44 | + } | ||
| 38 | 45 | } else { | |
| 39 | 46 | ret = StringBytes::Encode( | |
| 40 | 47 | isolate, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,6 +201,13 @@ assert.throws( | |||
| 201 | 201 | } | |
| 202 | 202 | ); | |
| 203 | 203 | ||
| 204 | + assert.throws( | ||
| 205 | + () => new StringDecoder().write(Buffer.alloc(0x1fffffe8 + 1).fill('a')), | ||
| 206 | + { | ||
| 207 | + code: 'ERR_STRING_TOO_LONG', | ||
| 208 | + } | ||
| 209 | + ); | ||
| 210 | + | ||
| 204 | 211 | // Test verifies that StringDecoder will correctly decode the given input | |
| 205 | 212 | // buffer with the given encoding to the expected output. It will attempt all | |
| 206 | 213 | // possible ways to write() the input buffer, see writeSequences(). The | |
| Back | FazBrowse Home | New Git URL |
0 commit comments