-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from whyrusleeping/schomatis/fix/deferred/max-…
…lengths deferred: restrict max length
- Loading branch information
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package typegen | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestDeferredMaxLengthSingle(t *testing.T) { | ||
var header bytes.Buffer | ||
if err := WriteMajorTypeHeader(&header, MajByteString, ByteArrayMaxLen+1); err != nil { | ||
t.Fatal("failed to write header") | ||
} | ||
|
||
var deferred Deferred | ||
err := deferred.UnmarshalCBOR(&header) | ||
if err != maxLengthError { | ||
t.Fatal("deferred: allowed more than the maximum allocation supported") | ||
} | ||
} | ||
|
||
func TestDeferredMaxLengthRecursive(t *testing.T) { | ||
var header bytes.Buffer | ||
for i := 0; i < MaxLength+1; i++ { | ||
if err := WriteMajorTypeHeader(&header, MajTag, 0); err != nil { | ||
t.Fatal("failed to write header") | ||
} | ||
} | ||
|
||
var deferred Deferred | ||
err := deferred.UnmarshalCBOR(&header) | ||
if err != maxLengthError { | ||
t.Fatal("deferred: allowed more than the maximum number of elements") | ||
} | ||
} |