Skip to content

Commit

Permalink
Merge pull request #17 from nlpodyssey/issue-16
Browse files Browse the repository at this point in the history
pickle: handle odd stack items length
  • Loading branch information
matteo-grella authored Mar 21, 2024
2 parents 15e0f17 + 4547443 commit 213a4a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pickle/pickle.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ func loadDict(u *Unpickler) error {
return err
}
d := types.NewDict()
itemsLen := len(items)
for i := 0; i < itemsLen; i += 2 {
n := len(items)
for i := 0; i < n-1; i += 2 {
d.Set(items[i], items[i+1])
}
u.append(d)
Expand Down
15 changes: 15 additions & 0 deletions pickle/pickle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package pickle

import (
"fmt"
"io"
"math/big"
"reflect"
"strings"
Expand Down Expand Up @@ -754,6 +755,20 @@ func TestP4Carray(t *testing.T) {
}
}

func TestIssue16(t *testing.T) {
var (
pkl = "\x28\x88\x88\x88\x88\x88\x88\x88\x64"
want = io.EOF
)
_, err := Loads(pkl)
if err == nil {
t.Fatalf("expected an error")
}
if got, want := err.Error(), want.Error(); got != want {
t.Fatalf("invalid error:\ngot= %q\nwant=%q", got, want)
}
}

// TODO: test BinPersId
// TODO: test Get
// TODO: test BinGet
Expand Down

0 comments on commit 213a4a5

Please sign in to comment.