Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
299f524d
Commit
299f524d
authored
Sep 07, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image/png: check zlib checksum during Decode
R=nigeltao CC=golang-dev
https://golang.org/cl/4987041
parent
f2460a8c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
4 deletions
+41
-4
reader.go
src/pkg/image/png/reader.go
+10
-0
reader_test.go
src/pkg/image/png/reader_test.go
+29
-2
invalid-crc32.png
src/pkg/image/png/testdata/invalid-crc32.png
+0
-0
invalid-noend.png
src/pkg/image/png/testdata/invalid-noend.png
+0
-0
invalid-trunc.png
src/pkg/image/png/testdata/invalid-trunc.png
+0
-0
invalid-zlib.png
src/pkg/image/png/testdata/invalid-zlib.png
+0
-0
writer_test.go
src/pkg/image/png/writer_test.go
+2
-2
No files found.
src/pkg/image/png/reader.go
View file @
299f524d
...
...
@@ -489,6 +489,16 @@ func (d *decoder) idatReader(idat io.Reader) (image.Image, os.Error) {
// The current row for y is the previous row for y+1.
pr
,
cr
=
cr
,
pr
}
// Check for EOF, to verify the zlib checksum.
n
,
err
:=
r
.
Read
(
pr
[
:
1
])
if
err
!=
os
.
EOF
{
return
nil
,
FormatError
(
err
.
String
())
}
if
n
!=
0
{
return
nil
,
FormatError
(
"too much pixel data"
)
}
return
img
,
nil
}
...
...
src/pkg/image/png/reader_test.go
View file @
299f524d
...
...
@@ -10,6 +10,7 @@ import (
"image"
"io"
"os"
"strings"
"testing"
)
...
...
@@ -41,7 +42,7 @@ var filenamesShort = []string{
"basn6a16"
,
}
func
readP
ng
(
filename
string
)
(
image
.
Image
,
os
.
Error
)
{
func
readP
NG
(
filename
string
)
(
image
.
Image
,
os
.
Error
)
{
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -183,7 +184,7 @@ func TestReader(t *testing.T) {
}
for
_
,
fn
:=
range
names
{
// Read the .png file.
img
,
err
:=
readP
ng
(
"testdata/pngsuite/"
+
fn
+
".png"
)
img
,
err
:=
readP
NG
(
"testdata/pngsuite/"
+
fn
+
".png"
)
if
err
!=
nil
{
t
.
Error
(
fn
,
err
)
continue
...
...
@@ -239,3 +240,29 @@ func TestReader(t *testing.T) {
}
}
}
var
readerErrors
=
[]
struct
{
file
string
err
string
}{
{
"invalid-zlib.png"
,
"zlib checksum error"
},
{
"invalid-crc32.png"
,
"invalid checksum"
},
{
"invalid-noend.png"
,
"unexpected EOF"
},
{
"invalid-trunc.png"
,
"unexpected EOF"
},
}
func
TestReaderError
(
t
*
testing
.
T
)
{
for
_
,
tt
:=
range
readerErrors
{
img
,
err
:=
readPNG
(
"testdata/"
+
tt
.
file
)
if
err
==
nil
{
t
.
Errorf
(
"decoding %s: missing error"
,
tt
.
file
)
continue
}
if
!
strings
.
Contains
(
err
.
String
(),
tt
.
err
)
{
t
.
Errorf
(
"decoding %s: %s, want %s"
,
tt
.
file
,
err
,
tt
.
err
)
}
if
img
!=
nil
{
t
.
Errorf
(
"decoding %s: have image + error"
)
}
}
}
src/pkg/image/png/testdata/invalid-crc32.png
0 → 100644
View file @
299f524d
1.26 KB
src/pkg/image/png/testdata/invalid-noend.png
0 → 100644
View file @
299f524d
1.25 KB
src/pkg/image/png/testdata/invalid-trunc.png
0 → 100644
View file @
299f524d
1.26 KB
src/pkg/image/png/testdata/invalid-zlib.png
0 → 100644
View file @
299f524d
1.26 KB
src/pkg/image/png/writer_test.go
View file @
299f524d
...
...
@@ -56,13 +56,13 @@ func TestWriter(t *testing.T) {
for
_
,
fn
:=
range
names
{
qfn
:=
"testdata/pngsuite/"
+
fn
+
".png"
// Read the image.
m0
,
err
:=
readP
ng
(
qfn
)
m0
,
err
:=
readP
NG
(
qfn
)
if
err
!=
nil
{
t
.
Error
(
fn
,
err
)
continue
}
// Read the image again, encode it, and decode it.
m1
,
err
:=
readP
ng
(
qfn
)
m1
,
err
:=
readP
NG
(
qfn
)
if
err
!=
nil
{
t
.
Error
(
fn
,
err
)
return
...
...
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