Commit a97135c Or Neeman
committed
1 parent 1489c3f commit a97135c Copy full SHA for a97135c
File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -952,7 +952,13 @@ func (s *Stream) readFull(buf []byte) (err error) {
952
952
n += nn
953
953
}
954
954
if err == io .EOF {
955
- err = io .ErrUnexpectedEOF
955
+ if n < len (buf ) {
956
+ err = io .ErrUnexpectedEOF
957
+ } else {
958
+ // Readers are allowed to give EOF even though the read succeeded.
959
+ // In such cases, we discard the EOF, like io.ReadFull() does.
960
+ err = nil
961
+ }
956
962
}
957
963
return err
958
964
}
Original file line number Diff line number Diff line change @@ -665,6 +665,26 @@ func TestDecodeWithByteReader(t *testing.T) {
665
665
})
666
666
}
667
667
668
+ func testDecodeWithEncReader (t * testing.T , n int ) {
669
+ s := strings .Repeat ("0" , n )
670
+ _ , r , _ := EncodeToReader (s )
671
+ var decoded string
672
+ err := Decode (r , & decoded )
673
+ if err != nil {
674
+ t .Errorf ("Unexpected decode error with n=%v: %v" , n , err )
675
+ }
676
+ if decoded != s {
677
+ t .Errorf ("Decode mismatch with n=%v" , n )
678
+ }
679
+ }
680
+
681
+ // This is a regression test checking that decoding from encReader
682
+ // works for RLP values of size 8192 bytes or more.
683
+ func TestDecodeWithEncReader (t * testing.T ) {
684
+ testDecodeWithEncReader (t , 8188 ) // length with header is 8191
685
+ testDecodeWithEncReader (t , 8189 ) // length with header is 8192
686
+ }
687
+
668
688
// plainReader reads from a byte slice but does not
669
689
// implement ReadByte. It is also not recognized by the
670
690
// size validation. This is useful to test how the decoder
You can’t perform that action at this time.
0 commit comments