Go version

go version go1.25.0 windows/arm64

Output of go env in your module/workspace:

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=1
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOARCH=arm64
set GOARM64=v8.0
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\qmuntaldiaz\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\qmuntaldiaz\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-mthreads -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\QMUNTA~1\AppData\Local\Temp\go-build2403191986=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=arm64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=C:\Users\qmuntaldiaz\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\qmuntaldiaz\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=on
set GOTELEMETRYDIR=C:\Users\qmuntaldiaz\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_arm64
set GOVCS=
set GOVERSION=go1.25.0
set GOWORK=
set PKG_CONFIG=pkg-config

What did you do?


import (
    "fmt"
    "io"
    "os"
    "syscall"
)

func main() {
    name, _ := syscall.UTF16PtrFromString("foo.txt")
    h, _ := syscall.CreateFile(name, syscall.GENERIC_READ|syscall.GENERIC_WRITE,
        0, nil, syscall.OPEN_ALWAYS, syscall.FILE_FLAG_OVERLAPPED, 0)

    f := os.NewFile(uintptr(h), "foo.txt")
    defer f.Close()

    content := []byte("foo")
    f.Write(content)
    n, _ := f.Seek(0, io.SeekCurrent)
    if n != int64(len(content)) {
        fmt.Printf("expected file pointer to be at offset %d, got %d", len(content), n)
    }
}

What did you see happen?

The offset returned by File.Seek is 3.

What did you expect to see?

The offset returned by File.Seek is 0.

Comment From: qmuntal

Note that this issue is a #74951 spin-off.

Comment From: qmuntal

@gopherbot please backport to Go 1.25. Support for Windows overlapped handles were introduces in Go 1.25, so Go 1.24 is not affected.

Comment From: gopherbot

Backport issue(s) opened: ~#75082 (for 1.24),~ #75083 (for 1.25).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

Comment From: gopherbot

Change https://go.dev/cl/697275 mentions this issue: os: set the correct file offset in File.Seek for Windows overlapped handles

Comment From: gabyhelp

Related Issues

Related Code Changes

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)