Skip to content

Commit 9f94511

Browse files
satyam kumargorkem
authored andcommitted
fix(harness): prevent OOM in verifyChecksum using stream
Resolves #1114 by replacing os.ReadFile with io.Copy to stream the file into the sha-256 hasher, rather than loading the whole file into memory first. Signed-off-by: satyam kumar <krsatyamthakur@gamil.com>
1 parent 925700b commit 9f94511

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

pkg/lib/harness/llm_download.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,18 @@ func verifyChecksum(folder, filename string, checksums map[string]string) error
176176
}
177177

178178
filePath := filepath.Join(folder, filename)
179-
fileData, err := os.ReadFile(filePath)
179+
file, err := os.Open(filePath)
180180
if err != nil {
181-
return fmt.Errorf("failed to read file %s: %w", filePath, err)
181+
return fmt.Errorf("failed to open file %s: %w", filePath, err)
182+
}
183+
defer file.Close()
184+
185+
hash := sha256.New()
186+
if _, err := io.Copy(hash, file); err != nil {
187+
return fmt.Errorf("failed to compute checksum for %s: %w", filePath, err)
182188
}
183189

184-
hash := sha256.Sum256(fileData)
185-
computedChecksum := hex.EncodeToString(hash[:])
190+
computedChecksum := hex.EncodeToString(hash.Sum(nil))
186191

187192
if computedChecksum != expectedChecksum {
188193
return fmt.Errorf("checksum mismatch for %s: expected %s, got %s", filename, expectedChecksum, computedChecksum)

0 commit comments

Comments
 (0)