mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-24 23:10:41 +02:00
format: bound the encoded adapter name symmetrically
DecodeLayout rejected names over 256 bytes while Encode accepted them, so an oversized name encoded fine and then failed every decode. Enforce the bound in Validate, shared by both directions.
This commit is contained in:
1 parent
9cb7dc7204
commit
4c7e5afbfe
2 files changed
+7
-1
No files matched your search
@@ -16,6 +16,8 @@ const (
|
||||
MaxExtentCount = 1 << 20
|
||||
// MaxPayloadBytes bounds the adapter payload carried in entry metadata.
|
||||
MaxPayloadBytes = 16 << 20
|
||||
// MaxFormatNameBytes bounds the encoded adapter name.
|
||||
MaxFormatNameBytes = 256
|
||||
)
|
||||
|
||||
// TotalSize returns the file size the layout describes.
|
||||
@@ -44,6 +46,9 @@ func (l *Layout) Validate(fileSize int64) error {
|
||||
if l.Format == "" {
|
||||
return fmt.Errorf("layout has no format name")
|
||||
}
|
||||
if len(l.Format) > MaxFormatNameBytes {
|
||||
return fmt.Errorf("layout format name is too long: %d bytes", len(l.Format))
|
||||
}
|
||||
if l.Align < 1 {
|
||||
return fmt.Errorf("layout align %d is invalid", l.Align)
|
||||
}
|
||||
@@ -97,7 +102,7 @@ func DecodeLayout(data []byte) (*Layout, error) {
|
||||
if err != nil || version != layoutVersion {
|
||||
return nil, fmt.Errorf("unsupported layout version")
|
||||
}
|
||||
name, err := readUvarintBytes(reader, 256)
|
||||
name, err := readUvarintBytes(reader, MaxFormatNameBytes)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read layout format: %w", err)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ func TestLayoutValidate(t *testing.T) {
|
||||
{"no extents", Layout{Format: "x", Align: 1}, -1, "no extents"},
|
||||
{"bad align", Layout{Format: "x", ExtentSizes: []int64{5}, Align: 0}, -1, "align"},
|
||||
{"no name", Layout{ExtentSizes: []int64{5}, Align: 1}, -1, "format name"},
|
||||
{"name too long", Layout{Format: strings.Repeat("x", MaxFormatNameBytes+1), ExtentSizes: []int64{5}, Align: 1}, -1, "too long"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
err := test.layout.Validate(test.fileSize)
|
||||
|
||||
Reference in new issue
Block a user