Skip to content

Commit

Permalink
Fix crash from unstable sort
Browse files Browse the repository at this point in the history
Fix in minio#12487 assumes that slices with tiebreaks are sorted equally.

That is only the case for "stable" sort versions.

Fixes nil result being returned in multi-pool setups.
  • Loading branch information
klauspost committed Jun 14, 2021
1 parent 264ee97 commit 97b0e8e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/erasure-server-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,10 @@ func (z *erasureServerPools) GetObjectNInfo(ctx context.Context, bucket, object
}
return mtime1.After(mtime2)
}
sort.Slice(errs, less)
sort.Slice(grs, less)

// Must be a stable sort for both slices to be sorted the same.
sort.SliceStable(errs, less)
sort.SliceStable(grs, less)

var found = -1
for i, err := range errs {
Expand Down Expand Up @@ -735,8 +737,9 @@ func (z *erasureServerPools) GetObjectInfo(ctx context.Context, bucket, object s
mtime2 := objInfos[j].ModTime
return mtime1.After(mtime2)
}
sort.Slice(errs, less)
sort.Slice(objInfos, less)
// Must be a stable sort for both slices to be sorted the same.
sort.SliceStable(errs, less)
sort.SliceStable(objInfos, less)

var found = -1
for i, err := range errs {
Expand Down

0 comments on commit 97b0e8e

Please sign in to comment.