]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix error unmarshalling bad metainfo nodes field
authorMatt Joiner <anacrolix@gmail.com>
Mon, 26 Jun 2023 09:48:23 +0000 (19:48 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 26 Jun 2023 09:48:23 +0000 (19:48 +1000)
metainfo/metainfo.go
metainfo/metainfo_test.go

index cd787260c150e972b8987713b65904a7f30c766b..fbf48671d484a0e3342f855585a98a91975c42f2 100644 (file)
@@ -10,10 +10,10 @@ import (
 )
 
 type MetaInfo struct {
-       InfoBytes    bencode.Bytes `bencode:"info,omitempty"`          // BEP 3
-       Announce     string        `bencode:"announce,omitempty"`      // BEP 3
-       AnnounceList AnnounceList  `bencode:"announce-list,omitempty"` // BEP 12
-       Nodes        []Node        `bencode:"nodes,omitempty"`         // BEP 5
+       InfoBytes    bencode.Bytes `bencode:"info,omitempty"`                              // BEP 3
+       Announce     string        `bencode:"announce,omitempty"`                          // BEP 3
+       AnnounceList AnnounceList  `bencode:"announce-list,omitempty"`                     // BEP 12
+       Nodes        []Node        `bencode:"nodes,omitempty,ignore_unmarshal_type_error"` // BEP 5
        // Where's this specified? Mentioned at
        // https://wiki.theory.org/index.php/BitTorrentSpecification: (optional) the creation time of
        // the torrent, in standard UNIX epoch format (integer, seconds since 1-Jan-1970 00:00:00 UTC)
index ee01c505ec68d6b4763b306eaee7f88c602fa62f..d1a6c356c42fa83d304f754e22db963edfdfdea7 100644 (file)
@@ -153,3 +153,11 @@ func TestStringCreationDate(t *testing.T) {
        var mi MetaInfo
        assert.NoError(t, bencode.Unmarshal([]byte("d13:creation date23:29.03.2018 22:18:14 UTC4:infodee"), &mi))
 }
+
+// See https://github.com/anacrolix/torrent/issues/843.
+func TestUnmarshalEmptyStringNodes(t *testing.T) {
+       var mi MetaInfo
+       c := qt.New(t)
+       err := bencode.Unmarshal([]byte("d5:nodes0:e"), &mi)
+       c.Assert(err, qt.IsNil)
+}