amass
                                
                                
                                
                                    amass copied to clipboard
                            
                            
                            
                        Occasional panic when marshaling results as json
When marshaling amass results as json, amass may panic with the following tracelog.
panic: reflect: slice index out of range [recovered]
         panic: reflect: slice index out of range
 goroutine 7992 [running]:
 encoding/json.(*encodeState).marshal.func1(0xc0031dee18)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/encode.go:328 +0x8d
 panic(0x1017140, 0x1a88070)
        /opt/hostedtoolcache/go/1.16.14/x64/src/runtime/panic.go:965 +0x1b9
reflect.Value.Index(0x1002420, 0xc013146860, 0x197, 0x1, 0x1130100, 0xc007a0d050, 0x199)
         /opt/hostedtoolcache/go/1.16.14/x64/src/reflect/value.go:962 +0x1f2
 encoding/json.arrayEncoder.encode(0xc01335a360, 0xc012835c80, 0x1002420, 0xc013146860, 0x197, 0x100)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/encode.go:915 +0x8d
 encoding/json.sliceEncoder.encode(0xc00e1201b0, 0xc012835c80, 0x1002420, 0xc013146860, 0x197, 0x100)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/encode.go:888 +0xfe
 encoding/json.structEncoder.encode(0xc00af31680, 0x5, 0x8, 0xc01335a390, 0xc012835c80, 0x1137fe0, 0xc013146840, 0x199, 0x2260100)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/encode.go:761 +0x2ab
 encoding/json.ptrEncoder.encode(0xc01335a3c0, 0xc012835c80, 0x107d0c0, 0xc013146840, 0x16, 0x1070100)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/encode.go:944 +0x125
 encoding/json.(*encodeState).reflectValue(0xc012835c80, 0x107d0c0, 0xc013146840, 0x16, 0xc0031d0100)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/encode.go:360 +0x82
 encoding/json.(*encodeState).marshal(0xc012835c80, 0x107d0c0, 0xc013146840, 0xc000360100, 0x0, 0x0)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/encode.go:332 +0xf9
 encoding/json.(*Encoder).Encode(0xc0031def40, 0x107d0c0, 0xc013146840, 0x0, 0x0)
         /opt/hostedtoolcache/go/1.16.14/x64/src/encoding/json/stream.go:206 +0x8b
 main.saveJSONOutput(0xc00023e1e0, 0xc0001d9b00, 0xc00036e840, 0xc00997a710)
         /home/runner/work/Amass/Amass/cmd/amass/enum.go:496 +0x272
 created by main.runEnumCommand
         /home/runner/work/Amass/Amass/cmd/amass/enum.go:227 +0xa65
Amass is called using amass enum -json amass_results.json -ipv4 -d example.com. The panic doesn't happen reliably and only happens like 1 in 50 times which makes me suspect that there is a race condition where occasionally another goroutine may still be writing data while json marshaling has already started, causing golang's json marshaler to panic. This suspicion is supported by the fact that amass is run on a system with 128 threads available which leaves more room for race conditions.