Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
og-rek
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
og-rek
Commits
1987330a
Commit
1987330a
authored
Jun 18, 2015
by
liaoqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
when line is too long, bufio.ReadLine may not read all data
parent
1b10364c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
15 deletions
+33
-15
ogórek.go
ogórek.go
+33
-15
No files found.
ogórek.go
View file @
1987330a
// Package
ogórek
is a library for decoding Python's pickle format.
// Package
gopickle
is a library for decoding Python's pickle format.
//
//
ogórek
is Polish for "pickle".
package
ogórek
//
gopickle
is Polish for "pickle".
package
gopickle
import
(
"bufio"
...
...
@@ -238,6 +238,22 @@ func (d Decoder) Decode() (interface{}, error) {
return
d
.
pop
(),
nil
}
func
(
d
*
Decoder
)
readLine
()
([]
byte
,
error
)
{
var
has_more
bool
=
true
var
line
[]
byte
=
[]
byte
{}
for
has_more
{
read_data
,
is_prefix
,
err
:=
d
.
r
.
ReadLine
()
if
err
!=
nil
{
return
line
,
err
}
has_more
=
is_prefix
for
i
:=
0
;
i
<
len
(
read_data
);
i
++
{
line
=
append
(
line
,
read_data
[
i
])
}
}
return
line
,
nil
}
// Push a marker
func
(
d
*
Decoder
)
mark
()
{
d
.
push
(
mark
{})
...
...
@@ -280,7 +296,7 @@ func (d *Decoder) dup() {
// Push a float
func
(
d
*
Decoder
)
loadFloat
()
error
{
line
,
_
,
err
:=
d
.
r
.
R
eadLine
()
line
,
err
:=
d
.
r
eadLine
()
if
err
!=
nil
{
return
err
}
...
...
@@ -294,7 +310,7 @@ func (d *Decoder) loadFloat() error {
// Push an int
func
(
d
*
Decoder
)
loadInt
()
error
{
line
,
_
,
err
:=
d
.
r
.
R
eadLine
()
line
,
err
:=
d
.
r
eadLine
()
if
err
!=
nil
{
return
err
}
...
...
@@ -342,7 +358,7 @@ func (d *Decoder) loadBinInt1() error {
// Push a long
func
(
d
*
Decoder
)
loadLong
()
error
{
line
,
_
,
err
:=
d
.
r
.
R
eadLine
()
line
,
err
:=
d
.
r
eadLine
()
if
err
!=
nil
{
return
err
}
...
...
@@ -422,7 +438,7 @@ func decodeStringEscape(b []byte) string {
// Push a string
func
(
d
*
Decoder
)
loadString
()
error
{
line
,
err
:=
d
.
r
.
ReadBytes
(
'\n'
)
line
,
err
:=
d
.
r
eadLine
(
)
if
err
!=
nil
{
return
err
}
...
...
@@ -437,11 +453,11 @@ func (d *Decoder) loadString() error {
return
fmt
.
Errorf
(
"invalid string delimiter: %c"
,
line
[
0
])
}
if
line
[
len
(
line
)
-
2
]
!=
delim
{
if
line
[
len
(
line
)
-
1
]
!=
delim
{
return
fmt
.
Errorf
(
"insecure string"
)
}
d
.
push
(
decodeStringEscape
(
line
[
1
:
len
(
line
)
-
2
]))
d
.
push
(
decodeStringEscape
(
line
[
1
:
len
(
line
)
-
1
]))
return
nil
}
...
...
@@ -477,7 +493,8 @@ func (d *Decoder) loadShortBinString() error {
}
func
(
d
*
Decoder
)
loadUnicode
()
error
{
line
,
_
,
err
:=
d
.
r
.
ReadLine
()
line
,
err
:=
d
.
readLine
()
if
err
!=
nil
{
return
err
}
...
...
@@ -485,9 +502,10 @@ func (d *Decoder) loadUnicode() error {
buf
:=
bytes
.
Buffer
{}
for
len
(
sline
)
>
=
6
{
for
len
(
sline
)
>
0
{
var
r
rune
var
err
error
r
,
_
,
sline
,
err
=
strconv
.
UnquoteChar
(
sline
,
'\'
'
)
if
err
!=
nil
{
return
err
...
...
@@ -548,11 +566,11 @@ type Class struct {
}
func
(
d
*
Decoder
)
global
()
error
{
module
,
_
,
err
:=
d
.
r
.
R
eadLine
()
module
,
err
:=
d
.
r
eadLine
()
if
err
!=
nil
{
return
err
}
name
,
_
,
err
:=
d
.
r
.
R
eadLine
()
name
,
err
:=
d
.
r
eadLine
()
if
err
!=
nil
{
return
err
}
...
...
@@ -602,7 +620,7 @@ func (d *Decoder) loadAppends() error {
}
func
(
d
*
Decoder
)
get
()
error
{
line
,
_
,
err
:=
d
.
r
.
R
eadLine
()
line
,
err
:=
d
.
r
eadLine
()
if
err
!=
nil
{
return
err
}
...
...
@@ -688,7 +706,7 @@ func (d *Decoder) obj() error {
}
func
(
d
*
Decoder
)
loadPut
()
error
{
line
,
_
,
err
:=
d
.
r
.
R
eadLine
()
line
,
err
:=
d
.
r
eadLine
()
if
err
!=
nil
{
return
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment