File tree 3 files changed +20
-0
lines changed
3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -463,6 +463,10 @@ func (tr *Reader) readHeader() *Header {
463
463
hdr .Uid = int (tr .octal (s .next (8 )))
464
464
hdr .Gid = int (tr .octal (s .next (8 )))
465
465
hdr .Size = tr .octal (s .next (12 ))
466
+ if hdr .Size < 0 {
467
+ tr .err = ErrHeader
468
+ return nil
469
+ }
466
470
hdr .ModTime = time .Unix (tr .octal (s .next (12 )), 0 )
467
471
s .next (8 ) // chksum
468
472
hdr .Typeflag = s .next (1 )[0 ]
Original file line number Diff line number Diff line change @@ -741,3 +741,19 @@ func TestUninitializedRead(t *testing.T) {
741
741
}
742
742
743
743
}
744
+
745
+ // Negative header size should not cause panic.
746
+ // Issues 10959 and 10960.
747
+ func TestNegativeHdrSize (t * testing.T ) {
748
+ f , err := os .Open ("testdata/neg-size.tar" )
749
+ if err != nil {
750
+ t .Fatal (err )
751
+ }
752
+ defer f .Close ()
753
+ r := NewReader (f )
754
+ _ , err = r .Next ()
755
+ if err != ErrHeader {
756
+ t .Error ("want ErrHeader, got" , err )
757
+ }
758
+ io .Copy (ioutil .Discard , r )
759
+ }
You can’t perform that action at this time.
0 commit comments