Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image/jpeg: panic: runtime error: index out of range #10154

Closed
needkane opened this issue Mar 13, 2015 · 1 comment
Closed

image/jpeg: panic: runtime error: index out of range #10154

needkane opened this issue Mar 13, 2015 · 1 comment
Milestone

Comments

@needkane
Copy link

@needkane needkane commented Mar 13, 2015

Image:
http://s3-us-west-2.amazonaws.com/qiniu-bs/panicImage

package main

import (
        "fmt"
        "image"
        "os"

        _ "image/jpeg"
)

func main(){
        f , _ := os.Open("panicImage")
        defer f.Close()
        m, _, err := image.Decode(f)
        if err != nil {
                fmt.Println("abnormal jpeg")
        }else{
                fmt.Println(m.ColorModel)
        }   
}
kane:qbox mac$ go run getPanic.go
Result:
goroutine 1 [running]:
image/jpeg.(*decoder).processSOS(0x102b6000, 0xa, 0x0, 0x0)
    /usr/local/go/src/image/jpeg/scan.go:143 +0x1e85
image/jpeg.(*decoder).decode(0x102b6000, 0x3027bad8, 0x102ac0c0, 0x102ac000, 0x0, 0x0, 0x0, 0x0)
    /usr/local/go/src/image/jpeg/reader.go:474 +0x53c
image/jpeg.Decode(0x3027bad8, 0x102ac0c0, 0x0, 0x0, 0x0, 0x0)
    /usr/local/go/src/image/jpeg/reader.go:498 +0x63
image.Decode(0x3027ba80, 0x102721b8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /usr/local/go/src/image/format.go:84 +0x106
main.main()
    /Users/mac/qbox/getPanic.go:14 +0x78

In my opinion:
No matter the image is normal or not ,panic was unexpected.
If the image is normal ,golang need give a normal result.
If the image is abnormal,golang should throw error not panic.
I modified the golang source code image/jpeg/scan.go

for i := 0; i < nComp; i++ {
                compIndex := scan[i].compIndex
+               if d.comp[compIndex].tq > maxTq {
+                   return FormatError("index is greater than maxTq")
+               }
                qt := &d.quant[d.comp[compIndex].tq]
                for j := 0; j < d.comp[compIndex].h*d.comp[compIndex].v; j++ {

I use golang contribute ,but i don't know if it works success or not.
jpeg panic

Change-Id: I45d8c88b84c47ac21adc814c25a426fa4aa1d209

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch needkane
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#       modified:   src/image/jpeg/scan.go
#
@minux minux added this to the Go1.5 milestone Mar 13, 2015
@minux
Copy link
Member

@minux minux commented Mar 13, 2015

/cc @nigeltao

Note: I slightly edited the issue description to apply some formatting.

Loading

@mikioh mikioh changed the title jpeg:panic: runtime error: index out of range image/jpeg: panic: runtime error: index out of range Mar 13, 2015
@nigeltao nigeltao closed this in 3eb84c8 Mar 13, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants