diff options
| author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-09-05 20:14:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-05 17:14:55 -0700 |
| commit | bc01f09e37785fb1f9bbc78f1546153e74721872 (patch) | |
| tree | 10fbed914a46b6f7c0efcfd950650ef936a94ea4 | |
| parent | f9e141a4126c3e243edb46b84bc3649a7e790bc8 (diff) | |
| download | seaweedfs-bc01f09e37785fb1f9bbc78f1546153e74721872.tar.xz seaweedfs-bc01f09e37785fb1f9bbc78f1546153e74721872.zip | |
Do CRC check if the buffer contains the full needle data before it is sent (#5980)
| -rw-r--r-- | weed/storage/volume_read.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/weed/storage/volume_read.go b/weed/storage/volume_read.go index 34b75660e..e18ce9016 100644 --- a/weed/storage/volume_read.go +++ b/weed/storage/volume_read.go @@ -164,6 +164,13 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr toWrite := min(count, int(offset+size-x)) if toWrite > 0 { crc = crc.Update(buf[0:toWrite]) + if offset == 0 && size == int64(n.DataSize) && int64(count) == size && (n.Checksum != crc) { + // This check works only if the buffer is big enough to hold the whole needle data + // and we ask for all needle data. + // Otherwise we cannot check the validity of partially aquired data. + stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorCRC).Inc() + return fmt.Errorf("ReadNeedleData checksum %v expected %v for Needle: %v,%v", crc, n.Checksum, v.Id, n) + } if _, err = writer.Write(buf[0:toWrite]); err != nil { return fmt.Errorf("ReadNeedleData write: %v", err) } @@ -182,7 +189,7 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr if offset == 0 && size == int64(n.DataSize) && (n.Checksum != crc && uint32(n.Checksum) != crc.Value()) { // the crc.Value() function is to be deprecated. this double checking is for backward compatible. stats.VolumeServerHandlerCounter.WithLabelValues(stats.ErrorCRC).Inc() - return fmt.Errorf("ReadNeedleData checksum %v expected %v", crc, n.Checksum) + return fmt.Errorf("ReadNeedleData checksum %v expected %v for Needle: %v,%v", crc, n.Checksum, v.Id, n) } return nil |
