fix: Handle unreadable PNG files when detecting diagrams.net images (#14685)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-23 09:03:25 -05:00
1 parent d624a240bc
commit 0fa4caec84
2 files changed
+24 -1

No files matched your search

+18
View File
@@ -43,4 +43,22 @@ describe("FileHelper", () => {
const unknown = new File(["x"], "notes.txt");
expect(FileHelper.withContentType(unknown)).toBe(unknown);
});
describe("getImageSourceAttr", () => {
it("returns undefined when the file cannot be read", async () => {
for (const type of ["image/png", "image/svg+xml"]) {
const file = new File(["x"], "image", { type });
const error = new DOMException(
"The requested file could not be read",
"NotReadableError"
);
vi.spyOn(file, "arrayBuffer").mockRejectedValue(error);
vi.spyOn(file, "text").mockRejectedValue(error);
await expect(FileHelper.getImageSourceAttr(file)).resolves.toBe(
undefined
);
}
});
});
});
+6 -1
View File
@@ -298,7 +298,12 @@ export default class FileHelper {
* @returns True if the file contains Draw.io/Diagrams.net data
*/
private static async isDiagramsNetPng(file: File): Promise<boolean> {
const buffer = await file.arrayBuffer();
let buffer: ArrayBuffer;
try {
buffer = await file.arrayBuffer();
} catch (_err) {
return false;
}
const bytes = new Uint8Array(buffer);
// Validate PNG signature