Cap each page's git output at 8 MiB
Browse filesSixteen renders at the 64 MiB core cap could need about 1 GiB, against the service's 640 MiB limit, so a public repository with a huge folder or ref list could get the server OOM-killed. Past the cap a page is now not found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Author
- Um9i vulgarmessiah@gmail.com
- Date
- 22 Nov 2026, 22:02
- Commit
- baecb32e1f77
- Parent
- 2badbef
1 file changed +12−2
| @@ -2,11 +2,17 @@ | ||
| use std::{sync::Arc, time::Duration}; | ||
| use gitv_core::{RepoDir, git, git_with_input}; | ||
| use gitv_core::{RepoDir, git_capped, git_with_input}; | ||
| use crate::cache::cached; | ||
| use crate::urls::{encode, join, lossy}; | ||
| /// The most output any one git command run for a page may produce. Pages render 16 at a time | ||
| /// in a service capped at 640 MiB, so this keeps a huge folder or ref list in a public | ||
| /// repository from running the server out of memory; past it, the page is "not found". It | ||
| /// fits about 80,000 folder entries or 60,000 refs, and files shown are capped far lower. | ||
| pub(crate) const PAGE_OUTPUT_LIMIT: usize = 8 << 20; | ||
| /// Objects an abbreviated id may match before it counts as too ambiguous to look up. | ||
| const MAX_CANDIDATES: usize = 1000; | ||
| const ENTRY_FORMAT: &str = "%H%x00%ct%x00%cI%x00%cd%x00%s%x00%B"; | ||
| @@ -92,8 +98,12 @@ impl Reader { | ||
| pub(super) fn new(dir: RepoDir) -> Self { | ||
| Self { dir, refs: OnceCell::new() } | ||
| } | ||
| /// A git command's output, or `None` if it fails or passes [`PAGE_OUTPUT_LIMIT`]. | ||
| pub(super) fn git_bytes<S: AsRef<OsStr>>(&self, args: &[S]) -> Option<Vec<u8>> { | ||
| git(&self.dir, args).ok() | ||
| match git_capped(&self.dir, args, PAGE_OUTPUT_LIMIT) { | ||
| Ok((output, false)) => Some(output), | ||
| _ => None, | ||
| } | ||
| } | ||
| pub(super) fn git<S: AsRef<OsStr>>(&self, args: &[S]) -> Option<String> { | ||