File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 9
9
"compress/gzip"
10
10
"debug/dwarf"
11
11
"encoding/binary"
12
+ "fmt"
12
13
"io"
13
14
"math/rand"
14
15
"net"
@@ -17,6 +18,7 @@ import (
17
18
"reflect"
18
19
"runtime"
19
20
"testing"
21
+ "time"
20
22
)
21
23
22
24
type fileTest struct {
@@ -954,3 +956,53 @@ func TestIssue10996(t *testing.T) {
954
956
t .Fatalf ("opening invalid ELF file unexpectedly succeeded" )
955
957
}
956
958
}
959
+
960
+ // TestInvalidBssSection is a regression test for golang.org/issue/54967.
961
+ //
962
+ // (*Section).Data should not use safeio to read data from the SHT_NOBITS
963
+ // section. Otherwise, when the section size is an incorrect huge value,
964
+ // it will result in OOM.
965
+ func TestInvalidBssSection (t * testing.T ) {
966
+ c := make (chan error )
967
+ go func () {
968
+ defer func () {
969
+ switch err := recover ().(type ) {
970
+ case nil :
971
+ c <- nil
972
+ case error :
973
+ c <- err
974
+ default :
975
+ c <- fmt .Errorf ("unexpected panic value: %T(%v)" , err , err )
976
+ }
977
+ }()
978
+
979
+ size := uint64 (3349099659509720927 )
980
+ s := new (Section )
981
+ s .SectionHeader = SectionHeader {
982
+ Name : ".bss" ,
983
+ Type : SHT_NOBITS ,
984
+ Flags : SHF_WRITE + SHF_ALLOC ,
985
+ Addr : 0x80496d4 ,
986
+ Offset : 0x6d4 ,
987
+ Size : size ,
988
+ Link : 0x0 ,
989
+ Info : 0x0 ,
990
+ Addralign : 0x4 ,
991
+ Entsize : 0x0 ,
992
+ FileSize : size ,
993
+ }
994
+ _ , _ = s .Data ()
995
+ }()
996
+
997
+ select {
998
+ case err := <- c :
999
+ wantErr := "runtime error: makeslice: len out of range"
1000
+ if err == nil {
1001
+ t .Errorf ("got error nil; want error %q" , wantErr )
1002
+ } else if errMsg := err .Error (); errMsg != wantErr {
1003
+ t .Errorf ("got error %q; want error %q" , errMsg , wantErr )
1004
+ }
1005
+ case <- time .After (time .Second ):
1006
+ t .Fatal ("test timed out (saferio.ReadData is called?)" )
1007
+ }
1008
+ }
You can’t perform that action at this time.
0 commit comments