Skip to content

Commit 1451162

Browse files
authored
Fix object ReadAt performs seek (#2197)
1 parent ffb7ec0 commit 1451162

6 files changed

Lines changed: 72 additions & 16 deletions

File tree

api-get-object.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,14 @@ func (o *Object) ReadAt(b []byte, offset int64) (n int, err error) {
458458
return 0, o.prevErr
459459
}
460460

461-
// Set the current offset to ReadAt offset, because the current offset will be shifted at the end of this method.
461+
// Save and restore currOffset so ReadAt doesn't affect sequential Read operations.
462+
// Per io.ReaderAt: "ReadAt should not affect nor be affected by the underlying seek offset."
463+
savedOffset := o.currOffset
464+
defer func() {
465+
o.currOffset = savedOffset
466+
o.seekData = true // Force next Read to re-establish stream at correct position
467+
}()
468+
462469
o.currOffset = offset
463470

464471
// Can only compare offsets to size when size has been set.

examples/minio/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ require (
1212
github.com/dustin/go-humanize v1.0.1 // indirect
1313
github.com/go-ini/ini v1.67.0 // indirect
1414
github.com/google/uuid v1.6.0 // indirect
15-
github.com/klauspost/compress v1.18.0 // indirect
15+
github.com/klauspost/compress v1.18.2 // indirect
1616
github.com/klauspost/cpuid/v2 v2.2.11 // indirect
1717
github.com/klauspost/crc32 v1.3.0 // indirect
18-
github.com/minio/crc64nvme v1.1.0 // indirect
18+
github.com/minio/crc64nvme v1.1.1 // indirect
1919
github.com/minio/md5-simd v1.1.2 // indirect
2020
github.com/philhofer/fwd v1.2.0 // indirect
2121
github.com/pmezard/go-difflib v1.0.0 // indirect
2222
github.com/rs/xid v1.6.0 // indirect
23-
github.com/tinylib/msgp v1.3.0 // indirect
24-
golang.org/x/crypto v0.45.0 // indirect
25-
golang.org/x/net v0.47.0 // indirect
26-
golang.org/x/sys v0.38.0 // indirect
27-
golang.org/x/text v0.31.0 // indirect
23+
github.com/tinylib/msgp v1.6.1 // indirect
24+
golang.org/x/crypto v0.46.0 // indirect
25+
golang.org/x/net v0.48.0 // indirect
26+
golang.org/x/sys v0.39.0 // indirect
27+
golang.org/x/text v0.32.0 // indirect
2828
gopkg.in/yaml.v3 v3.0.1 // indirect
2929
)
3030

examples/minio/go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
88
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
99
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
1010
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
11+
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
1112
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
1213
github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU=
1314
github.com/klauspost/cpuid/v2 v2.2.11/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
1415
github.com/klauspost/crc32 v1.3.0 h1:sSmTt3gUt81RP655XGZPElI0PelVTZ6YwCRnPSupoFM=
1516
github.com/klauspost/crc32 v1.3.0/go.mod h1:D7kQaZhnkX/Y0tstFGf8VUzv2UofNGqCjnC3zdHB0Hw=
1617
github.com/minio/crc64nvme v1.1.0 h1:e/tAguZ+4cw32D+IO/8GSf5UVr9y+3eJcxZI2WOO/7Q=
1718
github.com/minio/crc64nvme v1.1.0/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg=
19+
github.com/minio/crc64nvme v1.1.1/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg=
1820
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
1921
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
2022
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
@@ -27,14 +29,19 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
2729
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2830
github.com/tinylib/msgp v1.3.0 h1:ULuf7GPooDaIlbyvgAxBV/FI7ynli6LZ1/nVUNu+0ww=
2931
github.com/tinylib/msgp v1.3.0/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0=
32+
github.com/tinylib/msgp v1.6.1/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
3033
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
3134
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
35+
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
3236
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
3337
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
38+
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
3439
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
3540
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
41+
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
3642
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
3743
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
44+
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
3845
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3946
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4047
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

examples/s3/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ require github.com/minio/minio-go/v7 v7.0.73
1010
require (
1111
github.com/cheggaaa/pb v1.0.29
1212
github.com/minio/sio v0.3.0
13-
golang.org/x/crypto v0.45.0
13+
golang.org/x/crypto v0.46.0
1414
)
1515

1616
require (
1717
github.com/davecgh/go-spew v1.1.1 // indirect
1818
github.com/dustin/go-humanize v1.0.1 // indirect
1919
github.com/go-ini/ini v1.67.0 // indirect
2020
github.com/google/uuid v1.6.0 // indirect
21-
github.com/klauspost/compress v1.18.0 // indirect
21+
github.com/klauspost/compress v1.18.2 // indirect
2222
github.com/klauspost/cpuid/v2 v2.2.11 // indirect
2323
github.com/klauspost/crc32 v1.3.0 // indirect
2424
github.com/mattn/go-runewidth v0.0.14 // indirect
25-
github.com/minio/crc64nvme v1.1.0 // indirect
25+
github.com/minio/crc64nvme v1.1.1 // indirect
2626
github.com/minio/md5-simd v1.1.2 // indirect
2727
github.com/philhofer/fwd v1.2.0 // indirect
2828
github.com/pmezard/go-difflib v1.0.0 // indirect
2929
github.com/rivo/uniseg v0.4.4 // indirect
3030
github.com/rs/xid v1.6.0 // indirect
31-
github.com/tinylib/msgp v1.3.0 // indirect
32-
golang.org/x/net v0.47.0 // indirect
33-
golang.org/x/sys v0.38.0 // indirect
34-
golang.org/x/text v0.31.0 // indirect
31+
github.com/tinylib/msgp v1.6.1 // indirect
32+
golang.org/x/net v0.48.0 // indirect
33+
golang.org/x/sys v0.39.0 // indirect
34+
golang.org/x/text v0.32.0 // indirect
3535
gopkg.in/yaml.v3 v3.0.1 // indirect
3636
)
3737

examples/s3/go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1212
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1313
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
1414
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
15+
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
1516
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
1617
github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU=
1718
github.com/klauspost/cpuid/v2 v2.2.11/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
@@ -27,6 +28,7 @@ github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWV
2728
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
2829
github.com/minio/crc64nvme v1.1.0 h1:e/tAguZ+4cw32D+IO/8GSf5UVr9y+3eJcxZI2WOO/7Q=
2930
github.com/minio/crc64nvme v1.1.0/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg=
31+
github.com/minio/crc64nvme v1.1.1/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg=
3032
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
3133
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
3234
github.com/minio/sio v0.3.0 h1:syEFBewzOMOYVzSTFpp1MqpSZk8rUNbz8VIIc+PNzus=
@@ -44,22 +46,27 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
4446
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4547
github.com/tinylib/msgp v1.3.0 h1:ULuf7GPooDaIlbyvgAxBV/FI7ynli6LZ1/nVUNu+0ww=
4648
github.com/tinylib/msgp v1.3.0/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0=
49+
github.com/tinylib/msgp v1.6.1/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
4750
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4851
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
4952
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
5053
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
54+
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
5155
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
5256
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
5357
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
58+
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
5459
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5560
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5661
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5762
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5863
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
5964
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
65+
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
6066
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6167
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
6268
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
69+
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
6370
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
6471
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6572
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

functional_tests.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,6 @@ func testPutObjectWithAutoChecksums() {
20042004
// Save the data
20052005
objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "")
20062006
args["objectName"] = objectName
2007-
c.TraceOn(os.Stdout)
20082007

20092008
cmpChecksum := func(got, want string) {
20102009
if want != got {
@@ -5285,6 +5284,25 @@ func testGetObjectReadAtFunctional() {
52855284
}
52865285
offset += 512
52875286

5287+
readOffset := 0
5288+
bufRead := make([]byte, 512)
5289+
// Read (again) using the regular read function.
5290+
// Should not have been affected by ReadAt.
5291+
m, err = io.ReadFull(r, bufRead)
5292+
if err != nil {
5293+
logError(testName, function, args, startTime, "", "ReadFull failed", err)
5294+
return
5295+
}
5296+
if m != len(bufRead) {
5297+
logError(testName, function, args, startTime, "", "ReadFull read shorter bytes before reaching EOF, expected "+string(len(bufRead))+", got "+string(m), err)
5298+
return
5299+
}
5300+
if !bytes.Equal(bufRead, buf[readOffset:readOffset+len(bufRead)]) {
5301+
logError(testName, function, args, startTime, "", "Incorrect Read from offset", err)
5302+
return
5303+
}
5304+
readOffset += len(bufRead)
5305+
52885306
st, err := r.Stat()
52895307
if err != nil {
52905308
logError(testName, function, args, startTime, "", "Stat failed", err)
@@ -5310,6 +5328,23 @@ func testGetObjectReadAtFunctional() {
53105328
return
53115329
}
53125330

5331+
// Read (again) using the regular read function.
5332+
// Should not have been affected by ReadAt.
5333+
m, err = io.ReadFull(r, bufRead)
5334+
if err != nil {
5335+
logError(testName, function, args, startTime, "", "ReadFull (2) failed", err)
5336+
return
5337+
}
5338+
if m != len(bufRead) {
5339+
logError(testName, function, args, startTime, "", "ReadFull read shorter bytes before reaching EOF", err)
5340+
return
5341+
}
5342+
if !bytes.Equal(bufRead, buf[readOffset:readOffset+len(bufRead)]) {
5343+
logError(testName, function, args, startTime, "", "Incorrect Read from offset", err)
5344+
return
5345+
}
5346+
readOffset += len(bufRead)
5347+
53135348
offset += 512
53145349
m, err = r.ReadAt(buf3, offset)
53155350
if err != nil {

0 commit comments

Comments
 (0)