mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
refactor(managed): share user string diagnostics (#17411)
This commit is contained in:
@@ -319,13 +319,10 @@ export const readMetadataUserString = (
|
||||
const start = heap.offset + index;
|
||||
const decoded = compressedLength(bytes, start, scope, "userString");
|
||||
const content = start + decoded.prefix;
|
||||
const invalidUserString = (detail: string) =>
|
||||
managedFailure("invalid-string", scope, detail, start);
|
||||
if (content > heap.offset + heap.size - decoded.length)
|
||||
throw managedFailure(
|
||||
"invalid-string",
|
||||
scope,
|
||||
"User string leaves #US",
|
||||
start,
|
||||
);
|
||||
throw invalidUserString("User string leaves #US");
|
||||
const budget = managedDecodeBudget(layout);
|
||||
// A wider length prefix than the value needs still reads unambiguously, so
|
||||
// it is reported like the flag rather than discarding the literal. It is
|
||||
@@ -348,19 +345,13 @@ export const readMetadataUserString = (
|
||||
if (index === 0) {
|
||||
if (decoded.length === 0)
|
||||
return { offset: start, value: "", issues: conformance() };
|
||||
throw managedFailure(
|
||||
"invalid-string",
|
||||
scope,
|
||||
throw invalidUserString(
|
||||
`#US offset 0 is the reserved empty entry, but it encodes ${String(decoded.length)} byte(s)`,
|
||||
start,
|
||||
);
|
||||
}
|
||||
if (decoded.length % 2 !== 1)
|
||||
throw managedFailure(
|
||||
"invalid-string",
|
||||
scope,
|
||||
throw invalidUserString(
|
||||
"User string length is not UTF-16 code units plus one terminal flag byte",
|
||||
start,
|
||||
);
|
||||
const units = (decoded.length - 1) / 2;
|
||||
// Admit the literal before scanning it: JSON spends at most six bytes per
|
||||
|
||||
Reference in New Issue
Block a user