Skip to content

Commit f73674e

Browse files
committed
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>
1 parent 54a5095 commit f73674e

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/node_sea.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ void GetAsset(const FunctionCallbackInfo<Value>& args) {
829829
if (sea_resource.assets.empty()) {
830830
return;
831831
}
832-
auto it = sea_resource.assets.find(*key);
832+
auto it = sea_resource.assets.find(std::string_view(*key, key.length()));
833833
if (it == sea_resource.assets.end()) {
834834
return;
835835
}

test/fixtures/sea/assets/sea-config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"main": "sea.js",
33
"output": "sea-prep.blob",
44
"assets": {
5+
"a": "utf8_test_text.txt",
6+
"a\u0000b": "person.jpg",
57
"utf8_test_text.txt": "utf8_test_text.txt",
68
"person.jpg": "person.jpg"
79
}

test/fixtures/sea/assets/sea.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ assert(isSea());
5454
const textAssetOnDisk = readFileSync(process.env.__TEST_UTF8_TEXT_PATH, 'utf8');
5555
const binaryAssetOnDisk = readFileSync(process.env.__TEST_PERSON_JPG);
5656

57+
// Check asset keys containing NUL.
58+
{
59+
assert.strictEqual(getAsset('a', 'utf8'), textAssetOnDisk);
60+
assert.deepStrictEqual(Buffer.from(getAsset('a\0b')), binaryAssetOnDisk);
61+
}
62+
5763
// Check getAsset() buffer copies.
5864
{
5965
// Check that the asset embedded is the same as the original.

0 commit comments

Comments
 (0)