Files
seaweedfs/weed/server/volume_grpc_query.go
T
8bff3b3213 fix(volume): reject overflowing needle ID deltas (#10342)
* fix: reject overflowing needle ID deltas

Problem: Parsing a file ID with a delta can wrap a valid maximum needle ID back to zero without returning an error.

Root cause: Needle.ParsePath added the parsed uint64 delta without checking whether the sum exceeded the needle ID range.

Fix: Compare the delta with the remaining uint64 capacity before addition and return a contextual overflow error when it does not fit.

Validation: go test ./weed/storage/needle -run ^TestNeedleParsePathRejectsDeltaOverflow$ -count=1; go test ./weed/storage/needle -count=1; git diff --check 10cdaf381875492a2c752d1038797e96ff18208f..HEAD
Co-authored-by: Codex <noreply@openai.com>

* fix: propagate needle ID delta parse errors

Co-authored-by: Codex <noreply@openai.com>

* print the needle id in hex in the delta overflow error

* batch delete: keep processing after a cookie mismatch

* rust volume: reject overflowing needle id deltas

---------

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Chris Lu <chris.lu@gmail.com>
2026-07-15 23:24:04 -07:00

73 lines
1.8 KiB
Go

package weed_server
import (
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/operation"
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
"github.com/seaweedfs/seaweedfs/weed/query/json"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/tidwall/gjson"
)
func (vs *VolumeServer) Query(req *volume_server_pb.QueryRequest, stream volume_server_pb.VolumeServer_QueryServer) error {
for _, fid := range req.FromFileIds {
vid, id_cookie, err := operation.ParseFileId(fid)
if err != nil {
glog.V(0).Infof("volume query failed to parse fid %s: %v", fid, err)
return err
}
n := new(needle.Needle)
volumeId, _ := needle.NewVolumeId(vid)
if err := n.ParsePath(id_cookie); err != nil {
glog.V(0).Infof("volume query failed to parse fid %s: %v", fid, err)
return err
}
cookie := n.Cookie
if _, err := vs.store.ReadVolumeNeedle(volumeId, n, nil, nil); err != nil {
glog.V(0).Infof("volume query failed to read fid %s: %v", fid, err)
return err
}
if n.Cookie != cookie {
glog.V(0).Infof("volume query failed to read fid cookie %s: %v", fid, err)
return err
}
if req.InputSerialization.CsvInput != nil {
}
if req.InputSerialization.JsonInput != nil {
stripe := &volume_server_pb.QueriedStripe{
Records: nil,
}
filter := json.Query{
Field: req.Filter.Field,
Op: req.Filter.Operand,
Value: req.Filter.Value,
}
gjson.ForEachLine(string(n.Data), func(line gjson.Result) bool {
passedFilter, values := json.QueryJson(line.Raw, req.Selections, filter)
if !passedFilter {
return true
}
stripe.Records = json.ToJson(stripe.Records, req.Selections, values)
return true
})
err = stream.Send(stripe)
if err != nil {
return err
}
}
}
return nil
}