mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
sea: handle NUL bytes in asset keys
Construct the asset lookup string_view with the explicit Utf8Value length so embedded NUL bytes do not truncate keys. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/64773 Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
1 parent
bc6db3e879
commit
cf44862eb3
3 files changed
+9
-1
No files matched your search
+1
-1
@@ -841,7 +841,7 @@ void GetAsset(const FunctionCallbackInfo<Value>& args) {
|
||||
if (sea_resource.assets.empty()) {
|
||||
return;
|
||||
}
|
||||
auto it = sea_resource.assets.find(*key);
|
||||
auto it = sea_resource.assets.find(std::string_view(*key, key.length()));
|
||||
if (it == sea_resource.assets.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+2
@@ -2,6 +2,8 @@
|
||||
"main": "sea.js",
|
||||
"output": "sea-prep.blob",
|
||||
"assets": {
|
||||
"a": "utf8_test_text.txt",
|
||||
"a\u0000b": "person.jpg",
|
||||
"utf8_test_text.txt": "utf8_test_text.txt",
|
||||
"person.jpg": "person.jpg"
|
||||
}
|
||||
|
||||
Vendored
+6
@@ -54,6 +54,12 @@ assert(isSea());
|
||||
const textAssetOnDisk = readFileSync(process.env.__TEST_UTF8_TEXT_PATH, 'utf8');
|
||||
const binaryAssetOnDisk = readFileSync(process.env.__TEST_PERSON_JPG);
|
||||
|
||||
// Check asset keys containing NUL.
|
||||
{
|
||||
assert.strictEqual(getAsset('a', 'utf8'), textAssetOnDisk);
|
||||
assert.deepStrictEqual(Buffer.from(getAsset('a\0b')), binaryAssetOnDisk);
|
||||
}
|
||||
|
||||
// Check getAsset() buffer copies.
|
||||
{
|
||||
// Check that the asset embedded is the same as the original.
|
||||
|
||||
Reference in new issue
Block a user