Implemented better testing and fixed skipepd frames
This commit is contained in:
@@ -127,7 +127,12 @@ func (s SignalInfo) NumElements() int {
|
||||
if c == 0 {
|
||||
c = 1
|
||||
}
|
||||
return r * c
|
||||
/* HI-2: cap at 1M to prevent integer overflow / OOM from crafted packets */
|
||||
n := r * c
|
||||
if n < 0 || n > 1024*1024 {
|
||||
return 1024 * 1024
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// rawTypeSize returns the byte size for one element of the raw (unquantised) type.
|
||||
@@ -227,6 +232,11 @@ func ParseConfig(payload []byte) ([]SignalInfo, uint8, error) {
|
||||
return nil, 0, fmt.Errorf("config payload too short")
|
||||
}
|
||||
numSigs := binary.LittleEndian.Uint32(payload[0:4])
|
||||
/* HI-2: validate numSigs against payload length before allocating */
|
||||
maxSigs := uint32(len(payload) / SigDescSize)
|
||||
if numSigs > maxSigs {
|
||||
return nil, 0, fmt.Errorf("config claims %d signals but payload can hold at most %d", numSigs, maxSigs)
|
||||
}
|
||||
offset := 4
|
||||
sigs := make([]SignalInfo, 0, numSigs)
|
||||
for i := uint32(0); i < numSigs; i++ {
|
||||
@@ -327,6 +337,10 @@ func ParseData(payload []byte, sigs []SignalInfo, publishMode uint8, arrivalTime
|
||||
if numSamples == 0 {
|
||||
return []DataSample{}, nil
|
||||
}
|
||||
/* HI-2: sanity-cap numSamples to prevent OOM from crafted packets */
|
||||
if numSamples < 0 || numSamples > 1024*1024 {
|
||||
return nil, fmt.Errorf("accumulate numSamples %d out of range", numSamples)
|
||||
}
|
||||
|
||||
// Parse per-signal data blocks (all slots for a signal are contiguous).
|
||||
accumVals := make(map[string][]float64, len(sigs)) // scalars: numSamples values
|
||||
|
||||
Reference in New Issue
Block a user