<p dir="auto">Probably related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="83827505" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/11030" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/11030/hovercard" href="https://github.com/golang/go/issues/11030">#11030</a>.</p>
<p dir="auto">Running this produces an error:</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;compress/zlib&quot;
    &quot;fmt&quot;
    &quot;io&quot;
    &quot;log&quot;
)

var blob = []byte{
    0xa2, 0x02, 0x78, 0x9c, 0x05, 0x00, 0xb1, 0x09, 0xc0, 0x20,
    0xcc, 0xa5, 0xd0, 0x17, 0xdc, 0xbc, 0xa0, 0x44, 0x88, 0x1e,
    0xe1, 0x03, 0x4e, 0xc1, 0x49, 0xc8, 0x98, 0x0b, 0xbc, 0x41,
    0x3c, 0x2a, 0xb3, 0x5b, 0xe9, 0xdc, 0xb1, 0x47, 0x34, 0x44,
    0x80, 0x8c, 0x18, 0xb8, 0x5f, 0xc2, 0xe2, 0xe8, 0x48, 0x6d,
    0x3c, 0xf5, 0x3f, 0xcb, 0x5c, 0xe4, 0xdf, 0x4f, 0xb7, 0xde,
    0x06, 0xbb, 0xbd, 0x0e, 0x21, 0xb6, 0x02, 0x78, 0x9c, 0x1d,
    0xc8, 0x51, 0x0a, 0xc0, 0x20, 0x08, 0x00, 0xd0, 0x7f, 0x4f,
    0x21, 0xb2,
}

func main() {
    fmt.Printf(&quot;blob: % x\n&quot;, blob[2:])

    var buf = bytes.NewBuffer(blob[2:40])
    r, err := zlib.NewReader(buf)
    if err != nil {
        log.Fatal(err)
    }

    var out bytes.Buffer
    n, err := io.Copy(&amp;out, r)
    if err != nil {
        log.Fatal(err)
    }

    r.Close()

    fmt.Printf(&quot;io.Copy buf-&gt;out, %d bytes\n&quot;, n)
    fmt.Printf(&quot;out=% x\n&quot;, out.Bytes())
    fmt.Printf(&quot;buf=% x\n&quot;, buf.Bytes())
}"><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">"compress/zlib"</span>
    <span class="pl-s">"fmt"</span>
    <span class="pl-s">"io"</span>
    <span class="pl-s">"log"</span>
)

<span class="pl-k">var</span> <span class="pl-s1">blob</span> <span class="pl-c1">=</span> []<span class="pl-smi">byte</span>{
    <span class="pl-c1">0xa2</span>, <span class="pl-c1">0x02</span>, <span class="pl-c1">0x78</span>, <span class="pl-c1">0x9c</span>, <span class="pl-c1">0x05</span>, <span class="pl-c1">0x00</span>, <span class="pl-c1">0xb1</span>, <span class="pl-c1">0x09</span>, <span class="pl-c1">0xc0</span>, <span class="pl-c1">0x20</span>,
    <span class="pl-c1">0xcc</span>, <span class="pl-c1">0xa5</span>, <span class="pl-c1">0xd0</span>, <span class="pl-c1">0x17</span>, <span class="pl-c1">0xdc</span>, <span class="pl-c1">0xbc</span>, <span class="pl-c1">0xa0</span>, <span class="pl-c1">0x44</span>, <span class="pl-c1">0x88</span>, <span class="pl-c1">0x1e</span>,
    <span class="pl-c1">0xe1</span>, <span class="pl-c1">0x03</span>, <span class="pl-c1">0x4e</span>, <span class="pl-c1">0xc1</span>, <span class="pl-c1">0x49</span>, <span class="pl-c1">0xc8</span>, <span class="pl-c1">0x98</span>, <span class="pl-c1">0x0b</span>, <span class="pl-c1">0xbc</span>, <span class="pl-c1">0x41</span>,
    <span class="pl-c1">0x3c</span>, <span class="pl-c1">0x2a</span>, <span class="pl-c1">0xb3</span>, <span class="pl-c1">0x5b</span>, <span class="pl-c1">0xe9</span>, <span class="pl-c1">0xdc</span>, <span class="pl-c1">0xb1</span>, <span class="pl-c1">0x47</span>, <span class="pl-c1">0x34</span>, <span class="pl-c1">0x44</span>,
    <span class="pl-c1">0x80</span>, <span class="pl-c1">0x8c</span>, <span class="pl-c1">0x18</span>, <span class="pl-c1">0xb8</span>, <span class="pl-c1">0x5f</span>, <span class="pl-c1">0xc2</span>, <span class="pl-c1">0xe2</span>, <span class="pl-c1">0xe8</span>, <span class="pl-c1">0x48</span>, <span class="pl-c1">0x6d</span>,
    <span class="pl-c1">0x3c</span>, <span class="pl-c1">0xf5</span>, <span class="pl-c1">0x3f</span>, <span class="pl-c1">0xcb</span>, <span class="pl-c1">0x5c</span>, <span class="pl-c1">0xe4</span>, <span class="pl-c1">0xdf</span>, <span class="pl-c1">0x4f</span>, <span class="pl-c1">0xb7</span>, <span class="pl-c1">0xde</span>,
    <span class="pl-c1">0x06</span>, <span class="pl-c1">0xbb</span>, <span class="pl-c1">0xbd</span>, <span class="pl-c1">0x0e</span>, <span class="pl-c1">0x21</span>, <span class="pl-c1">0xb6</span>, <span class="pl-c1">0x02</span>, <span class="pl-c1">0x78</span>, <span class="pl-c1">0x9c</span>, <span class="pl-c1">0x1d</span>,
    <span class="pl-c1">0xc8</span>, <span class="pl-c1">0x51</span>, <span class="pl-c1">0x0a</span>, <span class="pl-c1">0xc0</span>, <span class="pl-c1">0x20</span>, <span class="pl-c1">0x08</span>, <span class="pl-c1">0x00</span>, <span class="pl-c1">0xd0</span>, <span class="pl-c1">0x7f</span>, <span class="pl-c1">0x4f</span>,
    <span class="pl-c1">0x21</span>, <span class="pl-c1">0xb2</span>,
}

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
    <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"blob: % x<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">blob</span>[<span class="pl-c1">2</span>:])

    <span class="pl-k">var</span> <span class="pl-s1">buf</span> <span class="pl-c1">=</span> <span class="pl-s1">bytes</span>.<span class="pl-en">NewBuffer</span>(<span class="pl-s1">blob</span>[<span class="pl-c1">2</span>:<span class="pl-c1">40</span>])
    <span class="pl-s1">r</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">zlib</span>.<span class="pl-en">NewReader</span>(<span class="pl-s1">buf</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-s1">log</span>.<span class="pl-en">Fatal</span>(<span class="pl-s1">err</span>)
    }

    <span class="pl-k">var</span> <span class="pl-s1">out</span> bytes.<span class="pl-smi">Buffer</span>
    <span class="pl-s1">n</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">io</span>.<span class="pl-en">Copy</span>(<span class="pl-c1">&amp;</span><span class="pl-s1">out</span>, <span class="pl-s1">r</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-s1">log</span>.<span class="pl-en">Fatal</span>(<span class="pl-s1">err</span>)
    }

    <span class="pl-s1">r</span>.<span class="pl-en">Close</span>()

    <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"io.Copy buf-&gt;out, %d bytes<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">n</span>)
    <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"out=% x<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">out</span>.<span class="pl-en">Bytes</span>())
    <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"buf=% x<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">buf</span>.<span class="pl-en">Bytes</span>())
}</pre></div>
<p dir="auto"><a href="http://play.golang.org/p/VjkLWbhsXl" rel="nofollow">Playground link</a></p>
<p dir="auto">I'm using <code class="notranslate">compress/zlib</code> heavily to process git packfiles and this error happens ocasionally.</p>
<p dir="auto">Versions tested:</p>
<ul dir="auto">
<li><code class="notranslate">go version go1.3.3 windows/amd64</code></li>
<li><code class="notranslate">go version go1.4.2 windows/amd64</code></li>
<li><code class="notranslate">go version go1.4.2 linux/amd64</code></li>
<li><code class="notranslate">go version go1.4.2 darwin/amd64</code></li>
</ul>
<p dir="auto">It's implementation related because Python (example is py3) does just fine:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; zlib.decompress(bytearray.fromhex(&quot;78 9c 05 00 b1 09 c0 20 cc a5 d0 17 dc bc a0 44 88 1e e1 03 4e c1 49 c8 98 0b bc 41 3c 2a b3 5b e9 dc b1 47 34 44 80 8c 18 b8 5f c2 e2 e8 48 6d 3c f5 3f cb 5c e4 df 4f b7 de 06 bb bd 0e 21&quot;))
b'100644 he.php\x00]\x055_~\xd9W\xff\x08J\x90\x92]\x19\xe3\xeb\xc6\xd0\xc6\xd7'"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">zlib</span>.<span class="pl-en">decompress</span>(<span class="pl-s1">bytearray</span>.<span class="pl-en">fromhex</span>(<span class="pl-s">"78 9c 05 00 b1 09 c0 20 cc a5 d0 17 dc bc a0 44 88 1e e1 03 4e c1 49 c8 98 0b bc 41 3c 2a b3 5b e9 dc b1 47 34 44 80 8c 18 b8 5f c2 e2 e8 48 6d 3c f5 3f cb 5c e4 df 4f b7 de 06 bb bd 0e 21"</span>))
<span class="pl-s">b'100644 he.php<span class="pl-cce">\x00</span>]<span class="pl-cce">\x05</span>5_~<span class="pl-cce">\xd9</span>W<span class="pl-cce">\xff</span><span class="pl-cce">\x08</span>J<span class="pl-cce">\x90</span><span class="pl-cce">\x92</span>]<span class="pl-cce">\x19</span><span class="pl-cce">\xe3</span><span class="pl-cce">\xeb</span><span class="pl-cce">\xc6</span><span class="pl-cce">\xd0</span><span class="pl-cce">\xc6</span><span class="pl-cce">\xd7</span>'</span></pre></div>
<p dir="auto">by <strong>milanbella</strong>:</p>
<pre class="notranslate">The problem is with calling postgres large object interface.  Normally calling
lo_close() on unlinked large object is safe, but if I do it in Go that will corrupt my
database.

I am attaching my C and Go test programs, both are same (difference being only
language). See my comments in Go program.

Create new database. Then run the Go program connecting to new database. If you run it
first time you shall see that you were able to open unlinked large object. If you run it
next time (and all next successive calls) lo_create() will always fail.  Also see my
comments in Go program.

The same C program is ok.


What is your $GOOS?  $GOARCH?
linux 386


Which revision are you using?  (hg identify)
5992bf56aa72 tip</pre>
<p dir="auto">Attachments:</p>
<ol dir="auto">
<li><a href="https://storage.googleapis.com/go-attachment/947/0/pgtest_go.tar" rel="nofollow">pgtest_go.tar</a> (10240 bytes)</li>
<li><a href="https://storage.googleapis.com/go-attachment/947/0/pgtest_c.tar" rel="nofollow">pgtest_c.tar</a> (10240 bytes)</li>
</ol>