diff options
author | Yureka <tvl@yuka.dev> | 2024-10-01T14·16+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-10-01T15·27+0000 |
commit | ab3555f5a7fa6347049159ee3a32730f9a0c637c (patch) | |
tree | ccaa0f3bec0feab2fdaaae8b7f9cabb9bfd23c37 /tvix/castore/src | |
parent | f0d5ed7074097ca44a86865ef82cdbd1d1bddff7 (diff) |
fix(tvix/castore/refscan): don't panic on empty patterns r/8747
Previously, the overlap calculation would underflow when the pattern is empty. Change-Id: I1f6bf49fafc4b8183a3a5e5e491a5a5bfc41ca97 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12558 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Autosubmit: yuka <yuka@yuka.dev>
Diffstat (limited to 'tvix/castore/src')
-rw-r--r-- | tvix/castore/src/refscan.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/tvix/castore/src/refscan.rs b/tvix/castore/src/refscan.rs index 0b8af296bb50..8e6a81b2a4fe 100644 --- a/tvix/castore/src/refscan.rs +++ b/tvix/castore/src/refscan.rs @@ -192,7 +192,15 @@ where self: Pin<&mut Self>, cx: &mut std::task::Context<'_>, ) -> Poll<std::io::Result<&[u8]>> { - let overlap = self.scanner.pattern.longest_candidate() - 1; + #[allow(clippy::manual_saturating_arithmetic)] // for clarity + let overlap = self + .scanner + .pattern + .longest_candidate() + .checked_sub(1) + // If this overflows (longest_candidate = 0), that means there are no needles, + // so there is no need to have any overlap + .unwrap_or(0); let mut this = self.project(); // Still data in buffer if *this.consumed < this.buffer.len() { |