mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
frame fuzzer: handle frames one by one (#3884)
This more closely matches what the connection does.
This commit is contained in:
parent
c52b583561
commit
30527c58c2
1 changed files with 16 additions and 21 deletions
|
@ -36,28 +36,17 @@ func Fuzz(data []byte) int {
|
|||
parser := wire.NewFrameParser(true)
|
||||
parser.SetAckDelayExponent(protocol.DefaultAckDelayExponent)
|
||||
|
||||
initialLen := len(data)
|
||||
|
||||
var frames []wire.Frame
|
||||
|
||||
var numFrames int
|
||||
var b []byte
|
||||
for len(data) > 0 {
|
||||
initialLen := len(data)
|
||||
l, f, err := parser.ParseNext(data, encLevel, version)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
data = data[l:]
|
||||
frames = append(frames, f)
|
||||
}
|
||||
parsedLen := initialLen - len(data)
|
||||
|
||||
if len(frames) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var b []byte
|
||||
for _, f := range frames {
|
||||
numFrames++
|
||||
if f == nil { // PADDING frame
|
||||
b = append(b, 0)
|
||||
continue
|
||||
}
|
||||
// We accept empty STREAM frames, but we don't write them.
|
||||
|
@ -67,21 +56,27 @@ func Fuzz(data []byte) int {
|
|||
continue
|
||||
}
|
||||
}
|
||||
lenBefore := len(b)
|
||||
b, err := f.Append(b, version)
|
||||
|
||||
startLen := len(b)
|
||||
parsedLen := initialLen - len(data)
|
||||
b, err = f.Append(b, version)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Error writing frame %#v: %s", f, err))
|
||||
}
|
||||
frameLen := len(b) - lenBefore
|
||||
if f.Length(version) != protocol.ByteCount(frameLen) {
|
||||
frameLen := protocol.ByteCount(len(b) - startLen)
|
||||
if f.Length(version) != frameLen {
|
||||
panic(fmt.Sprintf("Inconsistent frame length for %#v: expected %d, got %d", f, frameLen, f.Length(version)))
|
||||
}
|
||||
if sf, ok := f.(*wire.StreamFrame); ok {
|
||||
sf.PutBack()
|
||||
}
|
||||
if frameLen > protocol.ByteCount(parsedLen) {
|
||||
panic(fmt.Sprintf("Serialized length (%d) is longer than parsed length (%d)", len(b), parsedLen))
|
||||
}
|
||||
}
|
||||
if len(b) > parsedLen {
|
||||
panic(fmt.Sprintf("Serialized length (%d) is longer than parsed length (%d)", len(b), parsedLen))
|
||||
|
||||
if numFrames == 0 {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue