Skip to content

Commit b4c75a9

Browse files
daeyeondanielleadams
authored andcommitted
src: fix napi_check_object_type_tag()
This fixes a comparison failure occurring when the upper value of a type tag is 0, or a type tag value is 0. Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: #43788 Fixes: #43786 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 8c8c97d commit b4c75a9

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/js_native_api_v8.cc

+10-2
Original file line numberDiff line numberDiff line change
@@ -2452,8 +2452,16 @@ napi_status NAPI_CDECL napi_check_object_type_tag(napi_env env,
24522452
napi_type_tag tag;
24532453
val.As<v8::BigInt>()->ToWordsArray(
24542454
&sign, &size, reinterpret_cast<uint64_t*>(&tag));
2455-
if (size == 2 && sign == 0)
2456-
*result = (tag.lower == type_tag->lower && tag.upper == type_tag->upper);
2455+
if (sign == 0) {
2456+
if (size == 2) {
2457+
*result =
2458+
(tag.lower == type_tag->lower && tag.upper == type_tag->upper);
2459+
} else if (size == 1) {
2460+
*result = (tag.lower == type_tag->lower && 0 == type_tag->upper);
2461+
} else if (size == 0) {
2462+
*result = (0 == type_tag->lower && 0 == type_tag->upper);
2463+
}
2464+
}
24572465
}
24582466

24592467
return GET_RETURN_STATUS(env);

test/js-native-api/test_object/test.js

+9
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,23 @@ assert.strictEqual(newObject.test_string, 'test string');
163163
// Verify that objects can be type-tagged and type-tag-checked.
164164
const obj1 = test_object.TypeTaggedInstance(0);
165165
const obj2 = test_object.TypeTaggedInstance(1);
166+
const obj3 = test_object.TypeTaggedInstance(2);
167+
const obj4 = test_object.TypeTaggedInstance(3);
166168

167169
// Verify that type tags are correctly accepted.
168170
assert.strictEqual(test_object.CheckTypeTag(0, obj1), true);
169171
assert.strictEqual(test_object.CheckTypeTag(1, obj2), true);
172+
assert.strictEqual(test_object.CheckTypeTag(2, obj3), true);
173+
assert.strictEqual(test_object.CheckTypeTag(3, obj4), true);
170174

171175
// Verify that wrongly tagged objects are rejected.
172176
assert.strictEqual(test_object.CheckTypeTag(0, obj2), false);
173177
assert.strictEqual(test_object.CheckTypeTag(1, obj1), false);
178+
assert.strictEqual(test_object.CheckTypeTag(0, obj3), false);
179+
assert.strictEqual(test_object.CheckTypeTag(1, obj4), false);
180+
assert.strictEqual(test_object.CheckTypeTag(2, obj4), false);
181+
assert.strictEqual(test_object.CheckTypeTag(3, obj3), false);
182+
assert.strictEqual(test_object.CheckTypeTag(4, obj3), false);
174183

175184
// Verify that untagged objects are rejected.
176185
assert.strictEqual(test_object.CheckTypeTag(0, {}), false);

test/js-native-api/test_object/test_object.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,12 @@ static napi_value TestSeal(napi_env env,
605605
}
606606

607607
// We create two type tags. They are basically 128-bit UUIDs.
608-
static const napi_type_tag type_tags[2] = {
608+
static const napi_type_tag type_tags[5] = {
609609
{ 0xdaf987b3cc62481a, 0xb745b0497f299531 },
610-
{ 0xbb7936c374084d9b, 0xa9548d0762eeedb9 }
610+
{ 0xbb7936c374084d9b, 0xa9548d0762eeedb9 },
611+
{ 0xa5ed9ce2e4c00c38, 0 },
612+
{ 0, 0 },
613+
{ 0xa5ed9ce2e4c00c38, 0xdaf987b3cc62481a },
611614
};
612615

613616
static napi_value

0 commit comments

Comments
 (0)