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
60b23d0a
Commit
60b23d0a
authored
Feb 16, 2017
by
Kamil Kisiel
Committed by
GitHub
Feb 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27 from navytux/fix1
encoder: More unexpected EOF handling
parents
c7dbf2e4
a5094338
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
17 deletions
+26
-17
ogorek.go
ogorek.go
+7
-6
ogorek_test.go
ogorek_test.go
+19
-11
No files found.
ogorek.go
View file @
60b23d0a
...
@@ -246,6 +246,10 @@ loop:
...
@@ -246,6 +246,10 @@ loop:
if
err
==
errNotImplemented
{
if
err
==
errNotImplemented
{
return
nil
,
OpcodeError
{
key
,
insn
}
return
nil
,
OpcodeError
{
key
,
insn
}
}
}
// EOF from individual opcode decoder is unexpected end of stream
if
err
==
io
.
EOF
{
err
=
io
.
ErrUnexpectedEOF
}
return
nil
,
err
return
nil
,
err
}
}
}
}
...
@@ -468,8 +472,8 @@ func (d *Decoder) loadString() error {
...
@@ -468,8 +472,8 @@ func (d *Decoder) loadString() error {
return
fmt
.
Errorf
(
"invalid string delimiter: %c"
,
line
[
0
])
return
fmt
.
Errorf
(
"invalid string delimiter: %c"
,
line
[
0
])
}
}
if
line
[
len
(
line
)
-
1
]
!=
delim
{
if
l
en
(
line
)
<
2
||
l
ine
[
len
(
line
)
-
1
]
!=
delim
{
return
fmt
.
Errorf
(
"insecure string"
)
return
io
.
ErrUnexpectedEOF
}
}
d
.
push
(
decodeStringEscape
(
line
[
1
:
len
(
line
)
-
1
]))
d
.
push
(
decodeStringEscape
(
line
[
1
:
len
(
line
)
-
1
]))
...
@@ -531,10 +535,7 @@ func (d *Decoder) loadUnicode() error {
...
@@ -531,10 +535,7 @@ func (d *Decoder) loadUnicode() error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
_
,
err
=
buf
.
WriteRune
(
r
)
buf
.
WriteRune
(
r
)
if
err
!=
nil
{
return
err
}
}
}
if
len
(
sline
)
>
0
{
if
len
(
sline
)
>
0
{
return
fmt
.
Errorf
(
"characters remaining after loadUnicode operation: %s"
,
sline
)
return
fmt
.
Errorf
(
"characters remaining after loadUnicode operation: %s"
,
sline
)
...
...
ogorek_test.go
View file @
60b23d0a
...
@@ -6,6 +6,8 @@ import (
...
@@ -6,6 +6,8 @@ import (
"io"
"io"
"math/big"
"math/big"
"reflect"
"reflect"
"strconv"
"strings"
"testing"
"testing"
)
)
...
@@ -81,6 +83,23 @@ func TestDecode(t *testing.T) {
...
@@ -81,6 +83,23 @@ func TestDecode(t *testing.T) {
if
!
(
v
==
nil
&&
err
==
io
.
EOF
)
{
if
!
(
v
==
nil
&&
err
==
io
.
EOF
)
{
t
.
Errorf
(
"decode: no EOF at end: v = %#v err = %#v"
,
v
,
err
)
t
.
Errorf
(
"decode: no EOF at end: v = %#v err = %#v"
,
v
,
err
)
}
}
// for truncated input io.ErrUnexpectedEOF must be returned
for
l
:=
len
(
test
.
input
)
-
1
;
l
>
0
;
l
--
{
buf
:=
bytes
.
NewBufferString
(
test
.
input
[
:
l
])
dec
:=
NewDecoder
(
buf
)
//println(test.name, l)
v
,
err
:=
dec
.
Decode
()
// strconv.UnquoteChar used in loadUnicode always returns
// SyntaxError, at least unless the following CL is accepted:
// https://go-review.googlesource.com/37052
if
err
==
strconv
.
ErrSyntax
&&
strings
.
HasPrefix
(
test
.
name
,
"unicode"
)
{
err
=
io
.
ErrUnexpectedEOF
}
if
!
(
v
==
nil
&&
err
==
io
.
ErrUnexpectedEOF
)
{
t
.
Errorf
(
"%s: no ErrUnexpectedEOF on [:%d] truncated stream: v = %#v err = %#v"
,
test
.
name
,
l
,
v
,
err
)
}
}
}
}
}
}
...
@@ -110,17 +129,6 @@ func TestDecodeMultiple(t *testing.T) {
...
@@ -110,17 +129,6 @@ func TestDecodeMultiple(t *testing.T) {
}
}
}
}
func
TestDecodeUnexpectedEOF
(
t
*
testing
.
T
)
{
input
:=
"I5
\n
"
buf
:=
bytes
.
NewBufferString
(
input
)
dec
:=
NewDecoder
(
buf
)
obj
,
err
:=
dec
.
Decode
()
if
!
(
obj
==
nil
&&
err
==
io
.
ErrUnexpectedEOF
)
{
t
.
Errorf
(
"decode: no ErrUnexpectedEOF on truncated stream: obj = %#v err = %#v"
,
obj
,
err
)
}
}
func
TestZeroLengthData
(
t
*
testing
.
T
)
{
func
TestZeroLengthData
(
t
*
testing
.
T
)
{
data
:=
""
data
:=
""
output
,
err
:=
decodeLong
(
data
)
output
,
err
:=
decodeLong
(
data
)
...
...
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