1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Avoid exceptions in the console with ill-formed flate streams

It fixes #18876.
This commit is contained in:
Calixte Denizet 2024-10-10 10:09:04 +02:00
parent 233ac1773d
commit f2f56b6464
2 changed files with 19 additions and 4 deletions

View file

@ -161,8 +161,17 @@ class FlateStream extends DecodeStream {
try {
const { readable, writable } = new DecompressionStream("deflate");
const writer = writable.getWriter();
writer.write(bytes);
writer.close();
await writer.ready;
// We can't await writer.write() because it'll block until the reader
// starts which happens few lines below.
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});
const chunks = [];
let totalLength = 0;

View file

@ -71,8 +71,14 @@ async function writeStream(stream, buffer, transform) {
try {
const cs = new CompressionStream("deflate");
const writer = cs.writable.getWriter();
writer.write(bytes);
writer.close();
await writer.ready;
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});
// Response::text doesn't return the correct data.
const buf = await new Response(cs.readable).arrayBuffer();