From 9a3b599bd1d5d0657f9ed3e8776dbd4ea10ad2a3 Mon Sep 17 00:00:00 2001 From: jmeaster30 Date: Tue, 28 Mar 2023 22:20:48 -0400 Subject: [PATCH] Fixed issue with processing files that are less than 4096bytes --- libvore/bytecode.go | 2 +- libvore/vbufferedfile.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libvore/bytecode.go b/libvore/bytecode.go index bf9818a..6f3ee06 100644 --- a/libvore/bytecode.go +++ b/libvore/bytecode.go @@ -33,7 +33,7 @@ func findMatches(insts []SearchInstruction, all bool, skip int, take int, last i for currentState.status == INPROCESS { inst := insts[currentState.programCounter] currentState = inst.execute(currentState) - //fmt.Printf("PC: %d INST: %+v MATCH: '%s'\n", currentState.programCounter, inst, currentState.currentMatch) + //fmt.Printf("PC: %d INST: %+v STATE: %+v\n", currentState.programCounter, inst, currentState) if currentState.status == INPROCESS && currentState.programCounter >= len(insts) { currentState.SUCCESS() } diff --git a/libvore/vbufferedfile.go b/libvore/vbufferedfile.go index 96165a5..d28bac2 100644 --- a/libvore/vbufferedfile.go +++ b/libvore/vbufferedfile.go @@ -94,12 +94,20 @@ func (v *VBufferedFile) Seek(offset int64, whence int) (int64, error) { newStart = 0 } - if newStart >= v.fileSize-4096 { + fileBound := v.fileSize - 4096 + if fileBound < 0 { + fileBound = v.fileSize + } + if newStart >= fileBound { newStart = v.fileSize - 4096 + if newStart < 0 { + newStart = 0 + } } bytesRead, err := v.file.ReadAt(v.buffer, newStart) - if err != nil { + // it is actually expected to have an EOF error here when we are working with a file that is less than 4096 bytes + if err != nil && err != io.EOF { return v.currentOffset, err } v.minOffset = newStart