Discussion:
os.File.Seek() function panics on a pipe
g***@public.gmane.org
13 years ago
Permalink
Hello, when I am using the Seek function on a pipe, it panics. Shouldn't it
just generate an error? It also crashes in the sandbox when running
"pipe.go"

The code is: hello.go <http://play.golang.org/p/3VsQMI4Rx5> and pipe.go<http://play.golang.org/p/SGMeAHPxSi>

Building with "go build hello.go" and "go build pipe.go"
To execute type: ./hello | ./pipe

Debian 6.0 32 bit. Go 1.0.3

Gerard
Dave Cheney
13 years ago
Permalink
Received: by 10.50.195.161 with SMTP id if1mr1379970igc.0.1349654969396;
Sun, 07 Oct 2012 17:09:29 -0700 (PDT)
X-BeenThere: golang-dev-/***@public.gmane.org
Received: by 10.42.98.148 with SMTP id s20ls12009452icn.6.gmail; Sun, 07 Oct
2012 17:09:28 -0700 (PDT)
Received: by 10.43.53.144 with SMTP id vq16mr8999427icb.26.1349654968359;
Sun, 07 Oct 2012 17:09:28 -0700 (PDT)
Received: by 10.43.53.144 with SMTP id vq16mr8999426icb.26.1349654968347;
Sun, 07 Oct 2012 17:09:28 -0700 (PDT)
Received: from mail-oa0-f41.google.com (mail-oa0-f41.google.com [209.85.219.41])
by gmr-mx.google.com with ESMTPS id l2si504365igo.0.2012.10.07.17.09.28
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 07 Oct 2012 17:09:28 -0700 (PDT)
Received-SPF: neutral (google.com: 209.85.219.41 is neither permitted nor denied by best guess record for domain of dave-7L4Cwp9BzA+sTnJN9+***@public.gmane.org) client-ip=209.85.219.41;
Received: by mail-oa0-f41.google.com with SMTP id k14so3776198oag.0
for <golang-dev-/***@public.gmane.org>; Sun, 07 Oct 2012 17:09:28 -0700 (PDT)
Received: by 10.182.154.70 with SMTP id vm6mr12165740obb.50.1349654968078;
Sun, 07 Oct 2012 17:09:28 -0700 (PDT)
Received: by 10.76.71.137 with HTTP; Sun, 7 Oct 2012 17:09:28 -0700 (PDT)
In-Reply-To: <c215a3f5-43b5-4933-9522-346addf8f877-/***@public.gmane.org>
X-Gm-Message-State: ALoCoQn2jl2XGRHaN1pbsFcgFnQkCqmiymO+9gFhcc9mjNCXn5cfOMZ8boQT2W5+BdgHMXVWWLsL
X-Original-Sender: dave-7L4Cwp9BzA+sTnJN9+***@public.gmane.org
X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com:
209.85.219.41 is neither permitted nor denied by best guess record for domain
of dave-7L4Cwp9BzA+sTnJN9+***@public.gmane.org) smtp.mail=dave-7L4Cwp9BzA+sTnJN9+***@public.gmane.org
Precedence: list
Mailing-list: list golang-dev-/***@public.gmane.org; contact golang-dev+owners-/***@public.gmane.org
List-ID: <golang-dev.googlegroups.com>
X-Google-Group-Id: 1097896213209
List-Post: <http://groups.google.com/group/golang-dev/post?hl=en_US>, <mailto:golang-dev-/***@public.gmane.org>
List-Help: <http://groups.google.com/support/?hl=en_US>, <mailto:golang-dev+help-/***@public.gmane.org>
List-Archive: <http://groups.google.com/group/golang-dev?hl=en_US>
Sender: golang-dev-/***@public.gmane.org
List-Subscribe: <http://groups.google.com/group/golang-dev/subscribe?hl=en_US>,
<mailto:golang-dev+subscribe-/***@public.gmane.org>
List-Unsubscribe: <http://groups.google.com/group/golang-dev/subscribe?hl=en_US>,
<mailto:googlegroups-manage+1097896213209+unsubscribe-/***@public.gmane.org>
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.go.devel/47749>

Thank you for your detailed bug report, but you forgot the most
important thing, the panic message.
Post by g***@public.gmane.org
Hello, when I am using the Seek function on a pipe, it panics. Shouldn't it
just generate an error? It also crashes in the sandbox when running
"pipe.go"
The code is: hello.go and pipe.go
Building with "go build hello.go" and "go build pipe.go"
To execute type: ./hello | ./pipe
Debian 6.0 32 bit. Go 1.0.3
Gerard
Brad Fitzpatrick
13 years ago
Permalink
It's the Stat call that's crashing the sandox, not Seek:

http://play.golang.org/p/iPi2W77KxD
Post by g***@public.gmane.org
Hello, when I am using the Seek function on a pipe, it panics. Shouldn't
it just generate an error? It also crashes in the sandbox when running
"pipe.go"
The code is: hello.go <http://play.golang.org/p/3VsQMI4Rx5> and pipe.go<http://play.golang.org/p/SGMeAHPxSi>
Building with "go build hello.go" and "go build pipe.go"
To execute type: ./hello | ./pipe
Debian 6.0 32 bit. Go 1.0.3
Gerard
Brad Fitzpatrick
13 years ago
Permalink
Uh, I didn't even notice you were calling Size. If you remove the method
call, you can see the real error without crashing:

http://play.golang.org/p/3tKUjEqdla
Post by Brad Fitzpatrick
http://play.golang.org/p/iPi2W77KxD
Post by g***@public.gmane.org
Hello, when I am using the Seek function on a pipe, it panics. Shouldn't
it just generate an error? It also crashes in the sandbox when running
"pipe.go"
The code is: hello.go <http://play.golang.org/p/3VsQMI4Rx5> and pipe.go<http://play.golang.org/p/SGMeAHPxSi>
Building with "go build hello.go" and "go build pipe.go"
To execute type: ./hello | ./pipe
Debian 6.0 32 bit. Go 1.0.3
Gerard
Gerard
13 years ago
Permalink
Ok, I updated pipe.go <http://play.golang.org/p/4I9PYraj1l> and now it only
shows the hello world string and the error message. I used Stat().Size()
only to show that it was actually a pipe (size=0).

when executing: ./hello | ./pipe

The output is:

Hello, 侖界

%v(PANIC=runtime error: invalid memory address or nil pointer dereference)
Gerard
13 years ago
Permalink
Ok, I narrowed it down a bit:

Running this <http://play.golang.org/p/NfQmImFu1T> code from the sandbox,
you get the message:
seek = 0, err = permission denied

Running the same code as a standalone program the output is:
seek = 0, err = %v(PANIC=runtime error: invalid memory address or nil
pointer dereference)
minux
13 years ago
Permalink
Post by Gerard
Running this <http://play.golang.org/p/NfQmImFu1T> code from the sandbox,
seek = 0, err = permission denied
Seems the sandbox is pretty strict, and only allows read and write to
existing
file descriptors.
Post by Gerard
seek = 0, err = %v(PANIC=runtime error: invalid memory address or nil
pointer dereference)
I can't reproduce this.
On OS X/FreeBSD/Linux the output is:
seek = 0, err = seek /dev/stdin: illegal seek

What OS do you use?
Gerard
13 years ago
Permalink
Post by Gerard
seek = 0, err = %v(PANIC=runtime error: invalid memory address or nil
Post by Gerard
pointer dereference)
I can't reproduce this.
seek = 0, err = seek /dev/stdin: illegal seek
What OS do you use?
Linux 32 bit Debian 6 (with vmware player)

Loading...