Commit 54bf4551 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[wasm-gc][inspector] Fix handling of very long type names

And also make sure that even long names don't get truncated.

Fixed: chromium:1216284
Change-Id: I2792b60ddeb40a87816cb54fb0414ef0dea45da0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2947409
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75059}
parent da45d855
......@@ -767,8 +767,12 @@ Handle<String> WasmSimd128ToString(Isolate* isolate, wasm::Simd128 s128) {
Handle<String> GetRefTypeName(Isolate* isolate, wasm::ValueType type,
wasm::NativeModule* module) {
const char* nullable = type.kind() == wasm::kOptRef ? " null" : "";
EmbeddedVector<char, 64> type_name;
bool is_nullable = type.kind() == wasm::kOptRef;
const char* null_str = is_nullable ? " null" : "";
// This length only needs to be enough for generated names like
// "(ref null $type12345)". For names coming from the name section,
// we'll dynamically allocate an appropriately sized vector.
EmbeddedVector<char, 32> type_name;
size_t len;
if (type.heap_type().is_generic()) {
const char* generic_name = "";
......@@ -795,23 +799,32 @@ Handle<String> GetRefTypeName(Isolate* isolate, wasm::ValueType type,
default:
UNREACHABLE();
}
len = SNPrintF(type_name, "(ref%s %s)", nullable, generic_name);
len = SNPrintF(type_name, "(ref%s %s)", null_str, generic_name);
} else {
int type_index = type.ref_index();
wasm::ModuleWireBytes module_wire_bytes(module->wire_bytes());
Vector<const char> name_vec = module_wire_bytes.GetNameOrNull(
module->GetDebugInfo()->GetTypeName(type_index));
if (name_vec.empty()) {
len = SNPrintF(type_name, "(ref%s $type%u)", nullable, type_index);
len = SNPrintF(type_name, "(ref%s $type%u)", null_str, type_index);
} else {
len = SNPrintF(type_name, "(ref%s $", nullable);
Vector<char> suffix = type_name.SubVector(len, type_name.size());
size_t required_length =
name_vec.size() + // length of provided name
7 + // length of "(ref $)"
(is_nullable ? 5 : 0); // length of " null" (optional)
Vector<char> long_type_name = Vector<char>::New(required_length);
len = SNPrintF(long_type_name, "(ref%s $", null_str);
Vector<char> suffix =
long_type_name.SubVector(len, long_type_name.size());
// StrNCpy requires that there is room for an assumed trailing \0...
DCHECK_EQ(suffix.size(), name_vec.size() + 1);
StrNCpy(suffix, name_vec.data(), name_vec.size());
len += std::min(suffix.size(), name_vec.size());
if (len < type_name.size()) {
type_name[len] = ')';
len++;
}
// ...but we actually write ')' into that byte.
long_type_name[required_length - 1] = ')';
Handle<String> result =
isolate->factory()->InternalizeString(long_type_name);
long_type_name.Dispose();
return result;
}
}
return isolate->factory()->InternalizeString(type_name.SubVector(0, len));
......
......@@ -3,10 +3,10 @@ Tests GC object inspection.
Running test: test
Instantiating.
Waiting for wasm script (ignoring first non-wasm script).
Setting breakpoint at offset 107 on script wasm://wasm/22e4830a
Setting breakpoint at offset 107 on script wasm://wasm/151aafd6
Calling main()
Paused:
Script wasm://wasm/22e4830a byte offset 107: Wasm opcode 0x21 (kExprLocalSet)
Script wasm://wasm/151aafd6 byte offset 107: Wasm opcode 0x21 (kExprLocalSet)
Scope:
at $main (0:107):
- scope (wasm-expression-stack):
......@@ -20,7 +20,7 @@ at $main (0:107):
object details:
$byte: 127 (i8)
$word: 32767 (i16)
$pointer: Struct ((ref $StrB))
$pointer: Struct ((ref $veryLongNameWithMoreThanOneHundredAndTwentyEightCharactersToTestThatWeAreHandlingStringBufferOverflowWithoutCrashing_ThisWontGetTruncated))
- scope (module):
instance: exports: "main" (Function)
module: Module
......
......@@ -86,7 +86,7 @@ const module_bytes = [
/////////////////////////// NAME SECTION //////////////////////////
0x00, // name section
0x4d, // section length
0xd4, 0x01, // section length
0x04, // length of "name"
0x6e, 0x61, 0x6d, 0x65, // "name"
......@@ -103,14 +103,27 @@ const module_bytes = [
0x76, 0x61, 0x72, 0x42, // "varB"
0x04, // "type names" subsection
0x13, // length of subsection
0x99, 0x01, // length of subsection
0x03, // number of entries
0x00, // type index
0x04, // name length
0x53, 0x74, 0x72, 0x41, // "StrA"
0x01, // type index
0x04, // name length
0x53, 0x74, 0x72, 0x42, // "StrB"
0x89, 0x01, // name length
// Called "$StrB" in other comments, actual name:
// "veryLongNameWithMoreThanOneHundredAndTwentyEightCharactersToTestThat
// WeAreHandlingStringBufferOverflowWithoutCrashing_ThisWontGetTruncated"
0x76, 0x65, 0x72, 0x79, 0x4c, 0x6f, 0x6e, 0x67, 0x4e, 0x61, 0x6d, 0x65, 0x57,
0x69, 0x74, 0x68, 0x4d, 0x6f, 0x72, 0x65, 0x54, 0x68, 0x61, 0x6e, 0x4f, 0x6e,
0x65, 0x48, 0x75, 0x6e, 0x64, 0x72, 0x65, 0x64, 0x41, 0x6e, 0x64, 0x54, 0x77,
0x65, 0x6e, 0x74, 0x79, 0x45, 0x69, 0x67, 0x68, 0x74, 0x43, 0x68, 0x61, 0x72,
0x61, 0x63, 0x74, 0x65, 0x72, 0x73, 0x54, 0x6f, 0x54, 0x65, 0x73, 0x74, 0x54,
0x68, 0x61, 0x74, 0x57, 0x65, 0x41, 0x72, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c,
0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x42, 0x75, 0x66, 0x66,
0x65, 0x72, 0x4f, 0x76, 0x65, 0x72, 0x66, 0x6c, 0x6f, 0x77, 0x57, 0x69, 0x74,
0x68, 0x6f, 0x75, 0x74, 0x43, 0x72, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x5f,
0x54, 0x68, 0x69, 0x73, 0x57, 0x6f, 0x6e, 0x74, 0x47, 0x65, 0x74, 0x54, 0x72,
0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x64,
0x02, // type index
0x04, // name length
0x41, 0x72, 0x72, 0x43, // "ArrC"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment