Skip to content
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: limit of C.CBytes #53965

Closed
cuiweixie opened this issue Jul 20, 2022 · 2 comments
Closed

cmd/cgo: limit of C.CBytes #53965

cuiweixie opened this issue Jul 20, 2022 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@cuiweixie
Copy link
Contributor

cuiweixie commented Jul 20, 2022

What version of Go are you using (go version)?

$ go version
go version go1.15.6 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOROOT/bin/go version: go version go1.15.6 windows/amd64
GOROOT/bin/go tool compile -V: compile version go1.15.6
gdb --version: GNU gdb (GDB) 8.1

What did you do?

package main

/*
#include <stdio.h>
void cprint(char * s) {
	printf("char %c\n", s[1024*1024*1024-1]);
	printf("char %c\n", s[1024*1024*1024]);
}
*/
import "C"

func main() {
	bs := make([]byte, 1<<30+10)
	bs[1024*1024*1024-1] = 'a'
	bs[1024*1024*1024] = 'b'
	t := C.CBytes(bs)
	C.cprint((*C.char)(t))
}

What did you expect to see?

char a
char b

What did you see instead?

char a
char

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 20, 2022
cuiweixie added a commit to cuiweixie/go that referenced this issue Jul 20, 2022
@gopherbot
Copy link

Change https://go.dev/cl/418494 mentions this issue: cmd/cgo: panic when length too large

cuiweixie added a commit to cuiweixie/go that referenced this issue Jul 20, 2022
@toothrot toothrot added NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Jul 20, 2022
@toothrot toothrot added this to the Backlog milestone Jul 20, 2022
@gopherbot
Copy link

Change https://go.dev/cl/418557 mentions this issue: cmd/cgo: allow cgo to pass strings or []bytes bigger than 1<<30

@randall77 randall77 self-assigned this Jul 20, 2022
@dmitshur dmitshur modified the milestones: Backlog, Go1.19 Aug 1, 2022
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 1, 2022
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
There's no real reason to limit to 1<<30 bytes. Maybe it would catch
some mistakes, but probably ones that would quickly manifest in other
ways.

We can't use the fancy new unsafe.Slice function because this code
may still be generated for people with 1.16 or earlier in their go.mod file.
Use unsafe shenanigans instead.

Fixes golang#53965
Fixes golang#53958

Change-Id: Ibfa095192f50276091d6c2532e8ccd7832b57ca8
Reviewed-on: https://go-review.googlesource.com/c/go/+/418557
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants