-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/cgo: cgo is broken ("cgo argument has Go pointer to Go pointer") #14426
Comments
Because @opennota thought "Unplanned" meant we weren't going to fix it, I'll assume the worst that this is a bad regression and tag it Go 1.6.1. I don't know anything other than @ianlancetaylor is the person to evaluate this. I was simply giving it any Milestone so it showed up as looked at. |
For the same input file, it reliably crashes, although it takes a different amount of loop iterations, and changing the code changes the amount of iterations. https://ffmpeg.org/doxygen/2.8/structAVPacket.html is the definition of the AVPacket struct. The pointer checker is complaining about the
The last value is considered a valid Go pointer, as it points into the bss section. I haven't looked into the meaning of the priv field or how ffmpeg comes up with the values. However, I do wonder if it demonstrates a more general problem with the way cgo checks for Go pointers. C can put arbitrary values in those fields (or simply not initialize them), and may not necessarily intend to ever access them as pointers. |
FFmpeg developer and Gopher here (who uses CGO unfortunately too much). Can you say which version of FFmpeg you tested this with? The code in Sorry if this is noise! |
@dwbuiten |
It looks as if my assumption was correct: I ported your example to C, added a touch to
My guess is that the when the packet is statically allocated in the library, it uses some memory that once was used by Go, perhaps, and by chance ends up with a pointer-like value, causing the CGO analysis to catch it and panic. I will submit for a fix to go into the older releases of FFmpeg. This is not a Go bug. |
I added However, like @dominikh I also wonder if this enforcing of the pointer passing rules will be a source of random, even if rare, crashes. |
@opennota, I'm having a similar problem with cgo and ffmpeg ( |
@dwbuiten, thanks for helping. |
Thanks for looking into this. The cgo pointer checks should only going to complain about Go pointers (that is, pointers into Go memory) that appear in Go memory. I have not looked at the code, but it sounds like C++ is taking uninitialized memory and copying it into Go memory, and that some of that uninitialized memory has a pointer type. If that is what is happening, then you have a big problem, and it's a good thing that the cgo pointer check is catching it. The garbage collector is not going to work properly if it can see invalid values with pointer types. |
@ianlancetaylor This is correct, since he/she is allocating the |
OK, closing as not a Go problem. |
This should fix leaving uninitialized pointers in priv which can confuse user applications. See: golang/go#14426 Only for release branches Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This should fix leaving uninitialized pointers in priv which can confuse user applications. See: golang/go#14426 Only or release branches Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This should fix leaving uninitialized pointers in priv which can confuse user applications. See: golang/go#14426 Only or release branches Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This should fix leaving uninitialized pointers in priv which can confuse user applications. See: golang/go#14426 Only or release branches Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
The implementation of the Cgo pointer passing rules seems to be broken. This Go/cgo program, using ffmpeg via cgo, panics on line 72 at seemingly random timestamps / loop iterations given a path to an .mp4 video file as a first argument. You may need to run it several times to get a panic - about 50% of the runs are successful.
The text was updated successfully, but these errors were encountered: