Commit Graph

125 Commits

Author SHA1 Message Date
Matt Joiner e13fd755ee
bencode: Only use unsafe.String for go>=1.20 2023-04-03 15:10:38 +10:00
Matt Joiner 872b11bd57
bencode: Support parsing strings into bool 2023-03-20 10:50:22 +11:00
Matt Joiner 8e0e36887f
Fix an issue parsing negative bencode string lengths
See the fuzz test in dht/krpc.
2023-01-04 01:25:26 +11:00
Matt Joiner 02b6ee9954
Add bencode.Bytes.GoString 2022-03-09 20:57:23 +11:00
deepsource-autofix[bot] e3d08999e1
Format code with gofumpt (#724)
This commit fixes the style issues introduced in b81470d according to the output
from gofumpt.

Details: https://deepsource.io/gh/anacrolix/torrent/transform/ccafd976-fc9a-4c8a-bbfe-bc36426e79cb/

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2022-02-11 22:45:12 +11:00
Matt Joiner 726eec2f8d bencode: Support decoding "" as dict key 2022-01-07 19:11:41 +11:00
Matt Joiner 071ade67ae bencode: Return ErrUnexpectedEOF instead of EOF in the middle of values 2022-01-07 19:11:41 +11:00
Matt Joiner 32097526fc Add bencode.Decoder.MaxStrLen 2022-01-07 19:11:41 +11:00
Matt Joiner 14ee69aaeb Add failing bencode fuzz input 2021-12-12 16:56:01 +11:00
Matt Joiner cd7e6dcd5c bencode: Avoid allocating interface string up front
This should fix crashes during fuzzing. It's not a complete fix, we really want to limit the amount a given Decode can allocate. Maybe Go isn't the right language for this.
2021-12-12 16:56:01 +11:00
Matt Joiner 79511abe6c bencode: Fix decoding integer with leading + 2021-12-12 16:56:01 +11:00
Matt Joiner 8764456d23 bencode: Enforce dict key ordering
Fix bencode dict key ordering in HTTP tracker test
2021-12-12 16:56:01 +11:00
Matt Joiner 78e48f71dd bencode incorrectly parsed integers with leading zeroes 2021-12-12 16:56:01 +11:00
Matt Joiner 42dca16753 Add bencode FuzzInterfaceRoundTrip 2021-12-12 16:56:01 +11:00
Matt Joiner c6ee03f449 gofumpt 2021-11-08 14:47:01 +11:00
Matt Joiner 59d5e17ace bencode: Fix marshalling of unaddressable array of bytes 2021-11-04 20:01:25 +11:00
Matt Joiner 68fdd41d89 bencode.Bytes: Tests and stricter checks 2021-11-02 17:28:05 +11:00
afjoseph b33b45baf4 [fuzz] Put +build tags to support go1.16 as well 2021-11-01 11:26:58 +11:00
Matt Joiner 446016cb27 bencode: Encode arrays of bytes as strings
This looks appropriate with the use of byte arrays in DHT for BEP44.
2021-10-28 16:21:23 +11:00
Matt Joiner 6156aebf71 Limit decoded bencode string lengths to 32 bits
Found in fuzzing
2021-09-29 16:56:01 +10:00
Matt Joiner fcf65ee56a Add some fuzzing seeds 2021-09-29 12:12:16 +10:00
Matt Joiner 10ecd4390a Fix parsing of strings that don't fit in memory 2021-09-29 12:11:58 +10:00
Matt Joiner 03f8ec7090 Fix fuzz comparison of big.Int 2021-09-29 12:11:17 +10:00
Matt Joiner 2daad6e564 Update fuzz to use new standard library support 2021-09-29 11:51:03 +10:00
Matt Joiner a9aec0bb79 Simplify bencode.Decoder.parseStringInterface 2021-09-29 09:50:01 +10:00
YenForYang 37455d3c6b
bencode: optimize `(*Decoder).parseStringInterface()` (#659) 2021-09-29 09:30:35 +10:00
YenForYang 7b19e81fc6
bencode: get type of `big.Int` without creating instance (#651)
Nope, it doesn't really matter. But anyway, see c084706c22/cryptobyte/asn1.go (L267)
2021-09-18 12:44:47 +10:00
YenForYang ed3b3ee5ca
bencode: simplify getting `marshalerType` and `unmarshalerType` (#652) 2021-09-18 12:43:53 +10:00
YenForYang d43769dc15
bencode: Simplify `(*Decoder).parseListInterface()` (#656)
Preserve as much type as possible (it'll be converted to an `interface{}` anyway, but we can return `[]interface{}` instead of `{}interface` here).
2021-09-18 12:42:20 +10:00
YenForYang f3a9ea5aa9
Prevent allocation when checking interface (#649) 2021-09-18 12:36:25 +10:00
YenForYang a8db640c62
Drop bradfitz/iter dependency (#605)
* Drop bradfitz/iter dependency

`range iter.N` looks nice and doesn't allocate, but unfortunately using a `range` expression blocks a function from being inlined wherever it's used (for now). It's not that we need inlining in all cases, but I do think a C-style for loop looks just as nice and is probably clearer to the majority. There also aren't any clear disadvantages to changing (unless you just happen to dislike the look of C)

* Update misc_test.go

* Update rlreader_test.go

* Update torrent_test.go

* Update bench_test.go

* Update client_test.go

* Update iplist_test.go

* Update mse_test.go

* Update peerconn_test.go

* Update peerconn.go

* Update order_test.go

* Update decoder_test.go

* Update main.go

* Update bench-piece-mark-complete.go

* Update main.go

* Update torrent.go

* Update iplist_test.go

* Update main.go
2021-09-14 13:46:50 +10:00
YenForYang 2203b3bcdf
Cheaper byte to string conversion (#602)
Revamped https://github.com/anacrolix/torrent/pull/587
2021-09-14 10:41:04 +10:00
Matt Joiner 5cb47021ac Fix possible misuse of reflect.StringHeader 2021-09-09 22:49:22 +10:00
Bora M. Alper 16176b762e
Add linter CI (#542)
* Add linter CI

Signed-off-by: Bora M. Alper <bora@boramalper.org>

* Make gosec CI ignore SHA1 and upload sarif

Signed-off-by: Bora M. Alper <bora@boramalper.org>

* Fix formatting of source files

Signed-off-by: Bora M. Alper <bora@boramalper.org>

* Make go vet ignore unkeyed composite literals and fix other warnings

Signed-off-by: Bora M. Alper <bora@boramalper.org>

* Make staticcheck ignore unused methods and fix other warnings

Signed-off-by: Bora M. Alper <bora@boramalper.org>

* Use golangci-lint

Signed-off-by: Bora M. Alper <bora@boramalper.org>
2021-08-16 11:11:31 +10:00
Matt Joiner 901a8b1b36 Don't panic on int parse failures
This means for UnmarshalTypeErrors we now include context. There are still some other error types remaining that are thrown up via panic.
2021-08-12 13:46:02 +10:00
Matt Joiner a76fad32eb Fix panic unmarshalling bencode dict into unsupported type 2021-08-12 12:16:53 +10:00
Matt Joiner 3b62b0054d Fix go:build directives 2021-07-14 14:35:52 +10:00
Matt Joiner 364c7d862e Add to bencode.Unmarshal doc comment 2021-06-21 17:58:04 +10:00
Matt Joiner 047cdbae0d bencode: Improve support for embedded structs 2021-06-07 13:01:40 +10:00
Matt Joiner 25d2eea12d bencode: Support anonymous embedded struct pointers
More to come if this line of improvement is retained.
2021-06-07 13:01:40 +10:00
Matt Joiner 259356ccd6 Rework bencode decoding so it might support embedded structs 2021-06-07 13:01:40 +10:00
Matt Joiner 9ded7e7e87 Use bytes.Reader instead of bytes.Buffer in a few places 2021-05-05 15:48:57 +10:00
Matt Joiner 376ff763fe Apply staticcheck 2020-02-20 11:09:57 +11:00
Matt Joiner cf85d70a5c bencode: Rename string_values->stringValues 2019-12-23 13:39:34 +11:00
Matt Joiner cb1bf0f413 goimports -local 2019-08-21 20:58:40 +10:00
Matt Joiner 95daebd067 bencode: Decode singleton lists of the expected type
Fixes #297.
2019-06-13 13:07:37 +10:00
Matt Joiner 8e86f45124 Code formatting 2019-06-13 13:06:25 +10:00
Matt Joiner d4584c2ca6 bencode: Improve UnmarshalTypeError string and list parsing error context
Helps with #297.
2019-06-13 12:35:11 +10:00
Matt Joiner 4ea8a70a05 vgo get -u 2019-03-19 20:43:51 +11:00
Matt Joiner 25cd79aa1c Fix benchmark not building with changes to krpc.Msg.Token 2019-01-21 22:53:42 +01:00