fix(filesystem): enforce symlink and decoded-text admission

This commit is contained in:
morluto
2026-10-13 13:39:57 +08:00
parent 2187e16f14
commit ec0b081371
4 changed files with 127 additions and 9 deletions
+14 -7
View File
@@ -117,13 +117,20 @@ const readBoundedText = async (
throwIfCancelled(operation, signal);
const truncated = length > budget;
// A prefix may end within a UTF-8 character; omit those trailing bytes.
const decoder = new TextDecoder("utf-8");
return {
text: decoder.decode(bytes.subarray(0, Math.min(length, budget)), {
stream: truncated,
}),
truncated,
};
try {
const decoder = new TextDecoder("utf-8", { fatal: true });
return {
text: decoder.decode(bytes.subarray(0, Math.min(length, budget)), {
stream: truncated,
}),
truncated,
};
} catch (cause: unknown) {
throw new AnalysisProtocolError(
`apktool produced invalid UTF-8 in ${path}`,
{ cause },
);
}
} finally {
await file.close();
}