<p dir="auto">Run the following program on the following input:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;bytes&quot;
    &quot;io/ioutil&quot;
    &quot;os&quot;
    &quot;golang.org/x/image/bmp&quot;
)

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(&amp;w, img)
    if err != nil {
        panic(err)
    }
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
    <span class="pl-s">"bytes"</span>
    <span class="pl-s">"io/ioutil"</span>
    <span class="pl-s">"os"</span>
    <span class="pl-s">"golang.org/x/image/bmp"</span>
)

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
    <span class="pl-s1">data</span>, <span class="pl-s1">_</span> <span class="pl-c1">:=</span> <span class="pl-s1">ioutil</span>.<span class="pl-en">ReadFile</span>(<span class="pl-s1">os</span>.<span class="pl-c1">Args</span>[<span class="pl-c1">1</span>])
    <span class="pl-s1">img</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">bmp</span>.<span class="pl-en">Decode</span>(<span class="pl-s1">bytes</span>.<span class="pl-en">NewReader</span>(<span class="pl-s1">data</span>))
    <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
        <span class="pl-k">return</span>
    }
    <span class="pl-k">var</span> <span class="pl-s1">w</span> bytes.<span class="pl-smi">Buffer</span>
    <span class="pl-s1">err</span> <span class="pl-c1">=</span> <span class="pl-s1">bmp</span>.<span class="pl-en">Encode</span>(<span class="pl-c1">&amp;</span><span class="pl-s1">w</span>, <span class="pl-s1">img</span>)
    <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
        <span class="pl-en">panic</span>(<span class="pl-s1">err</span>)
    }
}</pre></div>
<p dir="auto"><a href="https://drive.google.com/file/d/0B20Uwp8Hs1oCc1dwYXJlMTRna0E/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B20Uwp8Hs1oCc1dwYXJlMTRna0E/view?usp=sharing</a></p>
<p dir="auto">It crashes as:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
runtime.gopanic(0x4d6b40, 0xc20800e590)
    src/runtime/panic.go:477 +0x3fe fp=0xc208041c50 sp=0xc208041bd0
runtime.makeslice(0x4ac5a0, 0x3c00009f60, 0x3c00009f60, 0x0, 0x0, 0x0)
    src/runtime/slice.go:26 +0xce fp=0xc208041ca0 sp=0xc208041c50
golang.org/x/image/bmp.decodeRGB(0x7fe619a4d2d8, 0xc20800a480, 0x7fe619a4d0d0, 0xc20802e020, 0x400000aa, 0x3c, 0x0, 0x0, 0x0, 0x0, ...)
    src/golang.org/x/image/bmp/reader.go:57 +0x185 fp=0xc208041e30 sp=0xc208041ca0
golang.org/x/image/bmp.Decode(0x7fe619a4d2d8, 0xc20800a480, 0x0, 0x0, 0x0, 0x0)
    src/golang.org/x/image/bmp/reader.go:112 +0x15b fp=0xc208041ed0 sp=0xc208041e30
main.main()
    /tmp/bmp.go:12 +0x132 fp=0xc208041f90 sp=0xc208041ed0"><pre class="notranslate"><code class="notranslate">panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
runtime.gopanic(0x4d6b40, 0xc20800e590)
    src/runtime/panic.go:477 +0x3fe fp=0xc208041c50 sp=0xc208041bd0
runtime.makeslice(0x4ac5a0, 0x3c00009f60, 0x3c00009f60, 0x0, 0x0, 0x0)
    src/runtime/slice.go:26 +0xce fp=0xc208041ca0 sp=0xc208041c50
golang.org/x/image/bmp.decodeRGB(0x7fe619a4d2d8, 0xc20800a480, 0x7fe619a4d0d0, 0xc20802e020, 0x400000aa, 0x3c, 0x0, 0x0, 0x0, 0x0, ...)
    src/golang.org/x/image/bmp/reader.go:57 +0x185 fp=0xc208041e30 sp=0xc208041ca0
golang.org/x/image/bmp.Decode(0x7fe619a4d2d8, 0xc20800a480, 0x0, 0x0, 0x0, 0x0)
    src/golang.org/x/image/bmp/reader.go:112 +0x15b fp=0xc208041ed0 sp=0xc208041e30
main.main()
    /tmp/bmp.go:12 +0x132 fp=0xc208041f90 sp=0xc208041ed0
</code></pre></div>
<p dir="auto">I am on commit 65a798f031fd31a65574938bed2ec44c2bcba496</p>
<p dir="auto">Run the following program on the following input:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;bytes&quot;
    &quot;io/ioutil&quot;
    &quot;os&quot;
    &quot;golang.org/x/image/bmp&quot;
)

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(&amp;w, img)
    if err != nil {
        panic(err)
    }
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
    <span class="pl-s">"bytes"</span>
    <span class="pl-s">"io/ioutil"</span>
    <span class="pl-s">"os"</span>
    <span class="pl-s">"golang.org/x/image/bmp"</span>
)

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
    <span class="pl-s1">data</span>, <span class="pl-s1">_</span> <span class="pl-c1">:=</span> <span class="pl-s1">ioutil</span>.<span class="pl-en">ReadFile</span>(<span class="pl-s1">os</span>.<span class="pl-c1">Args</span>[<span class="pl-c1">1</span>])
    <span class="pl-s1">img</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">bmp</span>.<span class="pl-en">Decode</span>(<span class="pl-s1">bytes</span>.<span class="pl-en">NewReader</span>(<span class="pl-s1">data</span>))
    <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
        <span class="pl-k">return</span>
    }
    <span class="pl-k">var</span> <span class="pl-s1">w</span> bytes.<span class="pl-smi">Buffer</span>
    <span class="pl-s1">err</span> <span class="pl-c1">=</span> <span class="pl-s1">bmp</span>.<span class="pl-en">Encode</span>(<span class="pl-c1">&amp;</span><span class="pl-s1">w</span>, <span class="pl-s1">img</span>)
    <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
        <span class="pl-en">panic</span>(<span class="pl-s1">err</span>)
    }
}</pre></div>
<p dir="auto"><a href="https://drive.google.com/file/d/0B20Uwp8Hs1oCTzFrMndWMjNtTHM/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B20Uwp8Hs1oCTzFrMndWMjNtTHM/view?usp=sharing</a></p>
<p dir="auto">It crashes as:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">I am on commit 65a798f031fd31a65574938bed2ec44c2bcba496</p>