fix(tvix/castore/refscan): don't panic on empty patterns
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>
This commit is contained in:
		
							parent
							
								
									f0d5ed7074
								
							
						
					
					
						commit
						ab3555f5a7
					
				
					 1 changed files with 9 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -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() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue