cloudflare / cloudflare/workerd

🐛 Bug Report — TypeError: memory limit has been exceeded with inline `data:` URL

Open
#2,998 14 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

### What is happening

When serving an HTML file with a large (>10MB) inline `data:` URL resource, even a basic worker will halt the response and respond with:

```TypeError: Parser error: The memory limit has been exceeded.```

I thought this was simply the response size, _but this is not the case_.

- If I send the file as `text/plain`, the file will send through the worker
- If I generate a large HTML file with `/dev/random`, the file will send through the worker
- The response truncates right at the point in the file that a data URL starts

So, it does seem to me to be very specific to inline data URLs.

Does this imply the worker `fetch()` is somehow inspecting the data URL during streaming? This seems odd, but if so, is there a missing option to disable this?

### Reproducing

- Run a minimal worker
- Output an HTML file with a large inline data resource
- Try to fetch the file through the worker

Example data URL HTML generator:

```sh
#!/bin/sh
content=$(dd if=/dev/random bs=1MB count=10 | base64 -w0)
echo ""
```

Generate the HTML file and serve it:

```sh
% ./gen.sh > 10mb.html
% python -m http.server 9000
```

And the worker:

```js
export default {
async fetch(request, env, ctx) {
const response = await fetch("http://localhost:9000/10mb.html");
return response;
}
}
```

Run and try to fetch:

```sh
% wrangler dev test.js
% curl -o - http://localhost:8787 > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 25 0 25 0 0 46 0 --:--:-- --:--:-- --:--:-- 46
```

Notice only 25 bytes sent, which is the start of the `img` element

```
% dd if=10mb.html bs=25 count=1

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.