SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix(util): guard BytesToUint{16,32,64} against short input (#9713)
Chris Lu65d557cbb014
diff --git a/weed/util/bytes.go b/weed/util/bytes.goindex 43008c42f3..4e9ce1d15a 100644--- a/weed/util/bytes.go+++ b/weed/util/bytes.go@@ -33,6 +33,9 @@ func BytesToHumanReadable(b uint64) string {func BytesToUint64(b []byte) (v uint64) {length := uint(len(b))+ if length == 0 {+ return 0+ }for i := uint(0); i < length-1; i++ {v += uint64(b[i])v <<= 8@@ -42,6 +45,9 @@ func BytesToUint64(b []byte) (v uint64) {}func BytesToUint32(b []byte) (v uint32) {length := uint(len(b))+ if length == 0 {+ return 0+ }for i := uint(0); i < length-1; i++ {v += uint32(b[i])v <<= 8@@ -50,9 +56,15 @@ func BytesToUint32(b []byte) (v uint32) {return}func BytesToUint16(b []byte) (v uint16) {- v += uint16(b[0])- v <<= 8- v += uint16(b[1])+ length := uint(len(b))+ if length == 0 {+ return 0+ }+ for i := uint(0); i < length-1; i++ {+ v += uint16(b[i])+ v <<= 8+ }+ v += uint16(b[length-1])return}func Uint64toBytes(b []byte, v uint64) {