Allow parsing png files to fail if thumbnailing is successful (#10308)
This commit is contained in:
parent
3e340d5906
commit
f74867e57b
2 changed files with 31 additions and 11 deletions
|
@ -96,17 +96,22 @@ async function loadImageElement(imageFile: File): Promise<{
|
|||
// Thus we could slice the file down to only sniff the first 0x1000
|
||||
// bytes (but this makes extractPngChunks choke on the corrupt file)
|
||||
const headers = imageFile; //.slice(0, 0x1000);
|
||||
parsePromise = readFileAsArrayBuffer(headers).then((arrayBuffer) => {
|
||||
const buffer = new Uint8Array(arrayBuffer);
|
||||
const chunks = extractPngChunks(buffer);
|
||||
for (const chunk of chunks) {
|
||||
if (chunk.name === "pHYs") {
|
||||
if (chunk.data.byteLength !== PHYS_HIDPI.length) return false;
|
||||
return chunk.data.every((val, i) => val === PHYS_HIDPI[i]);
|
||||
parsePromise = readFileAsArrayBuffer(headers)
|
||||
.then((arrayBuffer) => {
|
||||
const buffer = new Uint8Array(arrayBuffer);
|
||||
const chunks = extractPngChunks(buffer);
|
||||
for (const chunk of chunks) {
|
||||
if (chunk.name === "pHYs") {
|
||||
if (chunk.data.byteLength !== PHYS_HIDPI.length) return false;
|
||||
return chunk.data.every((val, i) => val === PHYS_HIDPI[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("Failed to parse PNG", e);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
const [hidpi] = await Promise.all([parsePromise, imgPromise]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue