| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 537feec commit 13e7d54
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -960,30 +960,39 @@ function writeFloatBackwards(val, offset = 0) { | |||
| 960 | 960 | ||
| 961 | 961 | class FastBuffer extends Uint8Array {} | |
| 962 | 962 | ||
| 963 | - function asciiWrite(buf, string, offset = 0, length = buf.byteLength - offset) { | ||
| 963 | + function asciiWrite(buf, string, offset = 0, length) { | ||
| 964 | + offset = Number(offset); | ||
| 964 | 965 | if (offset < 0 || offset > buf.byteLength) { | |
| 965 | 966 | throw new ERR_BUFFER_OUT_OF_BOUNDS('offset'); | |
| 966 | 967 | } | |
| 968 | + if (length === undefined) length = buf.byteLength - offset; | ||
| 969 | + else length = Number(length); | ||
| 967 | 970 | if (length < 0 || length > buf.byteLength - offset) { | |
| 968 | 971 | throw new ERR_BUFFER_OUT_OF_BOUNDS('length'); | |
| 969 | 972 | } | |
| 970 | 973 | return asciiWriteStatic(buf, string, offset, length); | |
| 971 | 974 | } | |
| 972 | 975 | ||
| 973 | - function latin1Write(buf, string, offset = 0, length = buf.byteLength - offset) { | ||
| 976 | + function latin1Write(buf, string, offset = 0, length) { | ||
| 977 | + offset = Number(offset); | ||
| 974 | 978 | if (offset < 0 || offset > buf.byteLength) { | |
| 975 | 979 | throw new ERR_BUFFER_OUT_OF_BOUNDS('offset'); | |
| 976 | 980 | } | |
| 981 | + if (length === undefined) length = buf.byteLength - offset; | ||
| 982 | + else length = Number(length); | ||
| 977 | 983 | if (length < 0 || length > buf.byteLength - offset) { | |
| 978 | 984 | throw new ERR_BUFFER_OUT_OF_BOUNDS('length'); | |
| 979 | 985 | } | |
| 980 | 986 | return latin1WriteStatic(buf, string, offset, length); | |
| 981 | 987 | } | |
| 982 | 988 | ||
| 983 | - function utf8Write(buf, string, offset = 0, length = buf.byteLength - offset) { | ||
| 989 | + function utf8Write(buf, string, offset = 0, length) { | ||
| 990 | + offset = Number(offset); | ||
| 984 | 991 | if (offset < 0 || offset > buf.byteLength) { | |
| 985 | 992 | throw new ERR_BUFFER_OUT_OF_BOUNDS('offset'); | |
| 986 | 993 | } | |
| 994 | + if (length === undefined) length = buf.byteLength - offset; | ||
| 995 | + else length = Number(length); | ||
| 987 | 996 | if (length < 0 || length > buf.byteLength - offset) { | |
| 988 | 997 | throw new ERR_BUFFER_OUT_OF_BOUNDS('length'); | |
| 989 | 998 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1734,6 +1734,11 @@ void SlowWriteString(const FunctionCallbackInfo<Value>& args) { | |||
| 1734 | 1734 | size_t max_length = 0; | |
| 1735 | 1735 | ||
| 1736 | 1736 | THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &offset)); | |
| 1737 | + if (offset > ts_obj_length) { | ||
| 1738 | + return node::THROW_ERR_BUFFER_OUT_OF_BOUNDS( | ||
| 1739 | + env, "\"offset\" is outside of buffer bounds"); | ||
| 1740 | + } | ||
| 1741 | + | ||
| 1737 | 1742 | THROW_AND_RETURN_IF_OOB( | |
| 1738 | 1743 | ParseArrayIndex(env, args[3], ts_obj_length - offset, &max_length)); | |
| 1739 | 1744 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,3 +127,17 @@ assert.throws(() => { | |||
| 127 | 127 | }, common.expectsError({ | |
| 128 | 128 | code: 'ERR_BUFFER_OUT_OF_BOUNDS', | |
| 129 | 129 | })); | |
| 130 | + | ||
| 131 | + for (const method of ['asciiWrite', 'latin1Write', 'utf8Write']) { | ||
| 132 | + let calls = 0; | ||
| 133 | + const offset = { | ||
| 134 | + valueOf() { | ||
| 135 | + calls++; | ||
| 136 | + return 2; | ||
| 137 | + }, | ||
| 138 | + }; | ||
| 139 | + assert.throws(() => Buffer.alloc(1)[method]('ww', offset, 1), common.expectsError({ | ||
| 140 | + code: 'ERR_BUFFER_OUT_OF_BOUNDS', | ||
| 141 | + })); | ||
| 142 | + assert.strictEqual(calls, 1); | ||
| 143 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments