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
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
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
c6ee03f449
gofumpt
2021-11-08 14:47:01 +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
10ecd4390a
Fix parsing of strings that don't fit in memory
2021-09-29 12:11:58 +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
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
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
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
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
fc4fab91f5
Switch to goimports import sorting
...
Used to use sortimports, but it's old, and goimports seems to have an opinion now.
2018-11-02 23:12:01 +11:00
Matt Joiner
bf5552ae3c
bencode: Remove a lot of expensive allocations
2018-07-25 13:42:28 +10:00
Matt Joiner
61d5902786
bencode: Avoid an extra getTags call
2018-07-23 11:09:42 +10:00
Matt Joiner
341501bf93
bencode: Cache struct fields
2018-07-23 10:50:58 +10:00
Matt Joiner
a4a123b04e
Don't error on bencode dicts that can't be marshalled
...
Have seen metainfo announce-lists that are lists of dicts. Possibly ignoring type errors with a tag would be smarter but I'm undecided.
2018-07-11 15:33:41 +10:00
Matt Joiner
04fa1b8d4c
Support marshalling bencode strings into byte arrays
2018-07-11 15:22:29 +10:00
Matt Joiner
1f6ba94882
Make extended handshake a struct, and move a bunch of extended stuff into peer_protocol
2018-07-10 12:20:36 +10:00
Matt Joiner
fefeef4ee9
Merge branch 'dev'
2018-06-22 17:43:51 +10:00
Matt Joiner
c5cc570e42
bencode: Remove string allocation when parsing strings
2018-06-17 16:21:04 +10:00
ia
fd7b23e527
all: gofmt
...
Run standard gofmt command on project root.
- go version go1.10.3 darwin/amd64
Signed-off-by: ia <isaac.ardis@gmail.com>
2018-06-17 15:49:58 +10:00
Matt Joiner
d7225aed03
Fix #247
2018-04-13 17:07:19 +10:00
Matt Joiner
319e57d1c6
Rework conns to/and allow multiple DHT servers
...
This will help with #229 , and IPv6 support.
2018-04-12 11:41:07 +10:00
Matt Joiner
33bfa908d2
bencode.Decoder.Decode: Don't assume panic values are type error
2018-02-13 00:55:15 +11:00
Matt Joiner
4b5203851a
bencode: Support unmarshalling strings into slices of kind Uint8
2018-02-13 00:44:05 +11:00
Matt Joiner
1f3eace72f
bencode: Add ignore_unmarshal_type_error tag
2018-01-27 14:31:46 +11:00
Matt Joiner
0e32592f78
bencode: Give more descriptive errors when failing to parse dicts
2018-01-25 21:46:50 +11:00
Matt Joiner
f060f0cb02
Comment on bencode.Decoder.Offset
2017-11-05 15:45:30 +11:00
Matt Joiner
edf2495b1f
Expose bencode.Decoder.Offset
2017-11-05 15:42:37 +11:00
Matt Joiner
7b2561cea8
bencode: More renames
2016-08-26 14:51:38 +10:00
Matt Joiner
f2cbc873a5
bencode: Rename a bunch of slug case stuff
2016-08-26 13:13:30 +10:00
Matt Joiner
ac3b40ace3
bencode: Remove private types encoder and decoder
...
Instead the functionality is exposed directly on the public types.
2016-06-15 15:00:51 +10:00
Matt Joiner
9d1a33facc
bencode: Unembed the Reader type, and minimize the interface surface
...
Want to remove some unnecessary allocations.
2016-06-15 14:51:58 +10:00
Matt Joiner
5f4fdfbd3d
bencode: Improve unknown value type error
2015-11-03 23:21:10 +11:00
Matt Joiner
28c1536daf
bencode: When decoding a dict, if the final key is missing its value, don't treat that as an error.
...
I think I'm swayed here by the robustness principle/Postel's Law.
2015-10-02 00:13:43 +10:00
Matt Joiner
8949375bd6
bencode: Decode very large integers as big.Int if they overflow int64
2015-09-20 21:08:42 +10:00
Matt Joiner
0403d4185d
bencode: Simplify parse_int
2015-08-23 17:51:24 +10:00