Navigation Menu

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

x/sys/windows/registry: Remove arbitrary string limit from setStringValue #12493

Closed
folbricht opened this issue Sep 4, 2015 · 3 comments
Closed

Comments

@folbricht
Copy link

setStringValue in https://github.com/golang/sys/blob/master/windows/registry/value.go enforces a max string size of 1<<10 which is arbitrary (on some Windows versions there is no limit enforced, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms724872(v=vs.85).aspx). If the string is longer than that, the current function triggers slice bounds out of range.

Current implementation:

func (k Key) setStringValue(name string, valtype uint32, value string) error {
    v, err := syscall.UTF16FromString(value)
    if err != nil {
        return err
    }
    buf := (*[1 << 10]byte)(unsafe.Pointer(&v[0]))[:len(v)*2]
    return k.setValue(name, valtype, buf)
}

I propose using a byte buffer to do the []uint16 to []byte conversion, removing the string limit.

func (k Key) setStringValue(name string, valtype uint32, value string) error {
    v, err := syscall.UTF16FromString(value)
    if err != nil {
        return err
    }
    buf := new(bytes.Buffer)
    buf.Grow(len(v)*2)
    binary.Write(buf, binary.LittleEndian, v)
    return k.setValue(name, valtype, buf.Bytes())
}
@ianlancetaylor
Copy link
Contributor

Just change the 1 << 10 to 1 << 30. That number doesn't matter, as long as it is larger than len(v)*2.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Sep 4, 2015
@alexbrainman
Copy link
Member

Try this https://go-review.googlesource.com/14287

Alex

alexbrainman added a commit that referenced this issue Sep 4, 2015
Allow registry blobs to be as large as 500MB

Update #12493

Change-Id: I1d0e5c10772d25f8e7e17fed6e2e7dd12ca4e7cf
Reviewed-on: https://go-review.googlesource.com/14287
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@gopherbot
Copy link

CL https://golang.org/cl/14288 mentions this issue.

@golang golang locked and limited conversation to collaborators Sep 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants