@xynogen/pix-skills 0.10.4 → 0.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/remote.ts +18 -3
package/package.json
CHANGED
package/src/remote.ts
CHANGED
|
@@ -156,9 +156,24 @@ async function fetchBytes(
|
|
|
156
156
|
if (!response.ok) throw new Error(`Remote request failed (${response.status}): ${url}`);
|
|
157
157
|
const declared = Number(response.headers.get("content-length") ?? "0");
|
|
158
158
|
if (declared > maxBytes) throw new Error(`Remote file exceeds ${maxBytes} byte limit`);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return
|
|
159
|
+
// Stream with a running cap: content-length can be absent or wrong, and
|
|
160
|
+
// arrayBuffer() would buffer an unbounded body before any check.
|
|
161
|
+
if (!response.body) return Buffer.alloc(0);
|
|
162
|
+
const chunks: Uint8Array[] = [];
|
|
163
|
+
let total = 0;
|
|
164
|
+
const reader = response.body.getReader();
|
|
165
|
+
try {
|
|
166
|
+
for (;;) {
|
|
167
|
+
const { done, value } = await reader.read();
|
|
168
|
+
if (done) break;
|
|
169
|
+
total += value.byteLength;
|
|
170
|
+
if (total > maxBytes) throw new Error(`Remote file exceeds ${maxBytes} byte limit`);
|
|
171
|
+
chunks.push(value);
|
|
172
|
+
}
|
|
173
|
+
} finally {
|
|
174
|
+
reader.cancel().catch(() => {});
|
|
175
|
+
}
|
|
176
|
+
return Buffer.concat(chunks);
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
async function fetchText(
|