possible fix for rare panic

This commit is contained in:
ston1th 2022-10-08 13:45:12 +02:00
commit 88861102fd
4 changed files with 20 additions and 17 deletions

View file

@ -163,7 +163,7 @@ func (f *file) ReadAt(p []byte, pos int64) (n int, err error) {
defer f.rmu.Unlock()
cn, _, roff := align(pos)
var last bool
if f.r.cn != cn {
if f.r.cn != cn || roff >= int64(len(f.r.unread)) {
_, err = f.Seek(pos, io.SeekStart)
if err != nil {
return

View file

@ -77,6 +77,8 @@ func (r *reader) Read(p []byte) (int, error) {
return n, nil
}
var ErrDecrypt = errors.New("failed to decrypt and authenticate payload chunk")
func (r *reader) readChunk() (last bool, err error) {
if len(r.unread) != 0 {
panic("stream: internal error: readChunk called with dirty buffer")
@ -105,7 +107,7 @@ func (r *reader) readChunk() (last bool, err error) {
out, err = r.a.Open(r.outBuf, r.nonce[:], in, nil)
}
if err != nil {
return false, errors.New("failed to decrypt and authenticate payload chunk")
return false, ErrDecrypt
}
incNonce(&r.nonce)