Skip to content

x/image/bmp: out of memory #10399

Description

@dvyukov

Run the following program on the following input:

package main

import (
    "bytes"
    "io/ioutil"
    "os"
    "golang.org/x/image/bmp"
)

func main() {
    data, _ := ioutil.ReadFile(os.Args[1])
    img, err := bmp.Decode(bytes.NewReader(data))
    if err != nil {
        return
    }
    var w bytes.Buffer
    err = bmp.Encode(&w, img)
    if err != nil {
        panic(err)
    }
}

https://drive.google.com/file/d/0B20Uwp8Hs1oCTzFrMndWMjNtTHM/view?usp=sharing

It crashes as:

fatal error: runtime: out of memory

goroutine 1 [running]:
runtime.systemstack_switch()
    src/runtime/asm_amd64.s:216 fp=0xc208041b58 sp=0xc208041b50
runtime.mallocgc(0x1000000300, 0x4b27c0, 0x1, 0x0)
    src/runtime/malloc.go:625 +0x8f1 fp=0xc208041c28 sp=0xc208041b58
runtime.newarray(0x4b27c0, 0x1000000300, 0x1)
    src/runtime/malloc.go:736 +0xce fp=0xc208041c68 sp=0xc208041c28
runtime.makeslice(0x4ac5a0, 0x1000000300, 0x1000000300, 0x0, 0x0, 0x0)
    src/runtime/slice.go:32 +0x178 fp=0xc208041cb8 sp=0xc208041c68
golang.org/x/image/bmp.decodeNRGBA(0x7f87732092d8, 0xc208014420, 0x7f87732090d0, 0xc20802e020, 0x10, 0x4000000c, 0x1, 0x0, 0x0, 0x0, ...)
    src/golang.org/x/image/bmp/reader.go:83 +0x185 fp=0xc208041e30 sp=0xc208041cb8
golang.org/x/image/bmp.Decode(0x7f87732092d8, 0xc208014420, 0x0, 0x0, 0x0, 0x0)
    src/golang.org/x/image/bmp/reader.go:114 +0x1be fp=0xc208041ed0 sp=0xc208041e30
main.main()
    /tmp/bmp.go:12 +0x132 fp=0xc208041f90 sp=0xc208041ed0

I am on commit 65a798f031fd31a65574938bed2ec44c2bcba496

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions