Public: anyone can read this; the crew can change it.

A file too large to render in the viewer says its size and offers raw download, and never reads past the cap into memory #15689

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A text file one byte over the viewer's cap now gets the size and a download link, and the server no longer reads its body into memory. Before this, the page read any file up to 5 MB whole and only then threw the body away at the 1 MB render cap. tsc is clean and 69 tests across eight blob/viewer files pass.

Notes

shipped production is serving it deploy 496afdb

opened this

A text file one byte over the viewer's cap now gets the size and a download link, and the server no longer reads its body into memory. Before this, the page read any file up to 5 MB whole and only then threw the body away at the 1 MB render cap. tsc is clean and 69 tests across eight blob/viewer files pass. I did not run the whole suite: scripts/fast.ts said the diff reaches 638 test files.

The "too large" page, the size-from-git check and the cap itself already existed. This pull closes the gap between 1 MB and 5 MB for ordinary text.

  • Change: in src/view/local.ts, localSource.blob now reads the size from git first. For a reader that draws a page (prefix: true), drawCeiling(path) is the file kind's own render cap, never below TEXT_CAP (1 MB) and never above the 5 MB fetch ceiling. Past it the result is too_large with the size and a head, and no body.
  • Test: test/blob-text-cap.test.ts commits a .ts file at TEXT_CAP and one a byte over. The at-cap file renders. The over-cap one gets the "Over the 1 MB limit" notice, its source result has no body, and the download link serves all TEXT_CAP + 1 bytes.
  • Left alone: editors, the API and the contents route still read up to 5 MB. Kinds with a larger render cap (PDF, image, SQLite, G-code and so on) keep their ceilings. Binary files keep their existing path.

What I did not do:

  • Under 50 ms: I did not add a timing assertion, because the issue's own rule is to judge by what is read, not by the clock. The over-cap answer costs one stat plus a 64-byte-class head read.
  • .log and .txt files: these keep their existing "last 1,000 lines" tail view over the cap, with a download link, rather than a one-line notice. That feature (#13622) was deliberate, so I left it.
  • Link path: the link on that page is /media/<ref>/<path>?download=1, not /raw/…. It serves the same bytes, and the test proves it works.
  • Terminal screen: I did not touch src/tui/ or the docs, because no page or route was added or edited.

To try it: commit a text file of 1_000_001 bytes and open /<owner>/<repo>/blob/<ref>/<file> for the notice. A file of exactly 1_000_000 bytes renders.

No look: the page for a too-large file is unchanged.

Closes #15662

1 earlier comment · 1 event
commented

A text file one byte over the viewer's cap now gets the size and a download link, and the server no longer reads its body into memory. Before this, the page read any file up to 5 MB whole and only then threw the body away at the 1 MB render cap. tsc is clean and 69 tests across eight blob/viewer files pass. I did not run the whole suite: scripts/fast.ts said the diff reaches 638 test files.

The "too large" page, the size-from-git check and the cap itself already existed. This pull closes the gap between 1 MB and 5 MB for ordinary text.

  • Change: in src/view/local.ts, localSource.blob now reads the size from git first. For a reader that draws a page (prefix: true), drawCeiling(path) is the file kind's own render cap, never below TEXT_CAP (1 MB) and never above the 5 MB fetch ceiling. Past it the result is too_large with the size and a head, and no body.
  • Test: test/blob-text-cap.test.ts commits a .ts file at TEXT_CAP and one a byte over. The at-cap file renders. The over-cap one gets the "Over the 1 MB limit" notice, its source result has no body, and the download link serves all TEXT_CAP + 1 bytes.
  • Left alone: editors, the API and the contents route still read up to 5 MB. Kinds with a larger render cap (PDF, image, SQLite, G-code and so on) keep their ceilings. Binary files keep their existing path.

What I did not do:

  • Under 50 ms: I did not add a timing assertion, because the issue's own rule is to judge by what is read, not by the clock. The over-cap answer costs one stat plus a 64-byte-class head read.
  • .log and .txt files: these keep their existing "last 1,000 lines" tail view over the cap, with a download link, rather than a one-line notice. That feature (#13622) was deliberate, so I left it.
  • Link path: the link on that page is /media/<ref>/<path>?download=1, not /raw/…. It serves the same bytes, and the test proves it works.
  • Terminal screen: I did not touch src/tui/ or the docs, because no page or route was added or edited.

To try it: commit a text file of 1_000_001 bytes and open /<owner>/<repo>/blob/<ref>/<file> for the notice. A file of exactly 1_000_000 bytes renders.

No look: the page for a too-large file is unchanged.

Approved

Approved. The change is small and correct: for a drawing reader, localSource.blob now caps the read at drawCeiling(path) (kind cap, floor TEXT_CAP, ceiling 5 MB), so a 1 MB+1 text file gets the existing too_large notice from the git-reported size with no body read. The test commits files at and one byte over the cap and checks the notice, the working download link and the render at the cap. Preview answers 200. No page, route or TUI surface changed, so no terminal screen or feature doc is owed. Two next things: (1) kinds whose render cap is 5 MB (xml, csv, sarif, mail, etc.) are still read whole between 1 and 5 MB; decide per kind whether they need the same stat-first treatment or a prefix. (2) Add a cheap timing or bytes-read assertion for the over-cap path so the under-50 ms claim is guarded, and say in the notice-page copy for .log/.txt that the tail is shown.

commented

Left #15662 open: 1 unticked item remain (Above a stated cap (a named constant, with its reason beside it) the viewer answers a one-line page with the size and a raw link, in under 50 ms.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs