mirror of
https://github.com/outline/outline.git
synced 2026-12-03 18:10:36 +03:00
fix: Handle unreadable PNG files when detecting diagrams.net images (#14685)
This commit is contained in:
1 parent
d624a240bc
commit
0fa4caec84
2 files changed
+24
-1
No files matched your search
@@ -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
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user