]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix #247
authorMatt Joiner <anacrolix@gmail.com>
Fri, 13 Apr 2018 07:07:19 +0000 (17:07 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 13 Apr 2018 07:07:19 +0000 (17:07 +1000)
bencode/decode.go
metainfo/metainfo_test.go

index dc985aaf7dd94609027a516b8dd2be53cb87112e..2905aec94554dc56a59f3ef1211322fe3d016281 100644 (file)
@@ -495,8 +495,9 @@ func (d *Decoder) parseValue(v reflect.Value) (bool, error) {
                return true, nil
        default:
                if b >= '0' && b <= '9' {
-                       // string
-                       // append first digit of the length to the buffer
+                       // It's a string.
+                       d.buf.Reset()
+                       // Write the  first digit of the length to the buffer.
                        d.buf.WriteByte(b)
                        return true, d.parseString(v)
                }
index 89e69c345486bd4a4e0eb8330183c1cae66f105f..e54447ae5aadeebffb25a50171f5885dd15a1e24 100644 (file)
@@ -128,3 +128,12 @@ func TestMetainfoWithStringURLList(t *testing.T) {
        require.NoError(t, err)
        assert.Len(t, mi.UrlList, 1)
 }
+
+// https://github.com/anacrolix/torrent/issues/247
+//
+// The decoder buffer wasn't cleared before starting the next dict item after
+// a syntax error on a field with the ignore_unmarshal_type_error tag.
+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))
+}