stream: fix NewDecryptReaderAt EOF handling (#708)

Co-authored-by: Arpit Gupta <arpitb.lgupta1@gmail.com>
This commit is contained in:
Arpit Gupta
2026-08-29 13:45:51 +02:00
committed by GitHub
co-authored by Arpit Gupta
parent 2313f65737
commit b155aff565
2 changed files with 61 additions and 1 deletions
+9 -1
View File
@@ -374,7 +374,15 @@ func NewDecryptReaderAt(key []byte, src io.ReaderAt, size int64) (*DecryptReader
finalChunkOff := finalChunkIndex * encChunkSize
finalChunkSize := size - finalChunkOff
finalChunk := make([]byte, finalChunkSize)
if _, err := src.ReadAt(finalChunk, finalChunkOff); err != nil {
nn, err := src.ReadAt(finalChunk, finalChunkOff)
if err == io.EOF {
if int64(nn) != finalChunkSize {
err = io.ErrUnexpectedEOF
} else {
err = nil
}
}
if err != nil {
return nil, fmt.Errorf("failed to read final chunk: %w", err)
}
nonce := nonceForChunk(finalChunkIndex)