AlistGo/alist · error

negative file size

Error message

negative file size

What it means

The metadata's size field (original file size in bytes) must be non-negative. A negative value is physically impossible and would corrupt range math when the chunker reassembles the file, so unmarshalMetadata rejects it outright.

Source

Thrown at drivers/chunker/util.go:236

func unmarshalMetadata(data []byte) (*chunkMetadata, error) {
	if len(data) > maxMetadataSizeWrite {
		return nil, errors.New("metadata is too large")
	}
	if data == nil || len(data) < 2 || data[0] != '{' || data[len(data)-1] != '}' {
		return nil, errors.New("invalid json")
	}
	var meta metadataJSON
	if err := json.Unmarshal(data, &meta); err != nil {
		return nil, err
	}
	if meta.Version == nil || meta.Size == nil || meta.ChunkNum == nil {
		return nil, errors.New("missing required field")
	}
	if *meta.Version < 1 {
		return nil, errors.New("wrong version")
	}
	if *meta.Size < 0 {
		return nil, errors.New("negative file size")
	}
	if *meta.ChunkNum < 1 || *meta.ChunkNum > maxSafeChunkNumber {
		return nil, errors.New("wrong number of chunks")
	}
	if meta.MD5 != "" {
		if _, err := hex.DecodeString(meta.MD5); err != nil || len(meta.MD5) != 32 {
			return nil, errors.New("wrong md5 hash")
		}
	}
	if meta.SHA1 != "" {
		if _, err := hex.DecodeString(meta.SHA1); err != nil || len(meta.SHA1) != 40 {
			return nil, errors.New("wrong sha1 hash")
		}
	}
	if *meta.Version > chunkerMetadataVerion {
		return nil, errors.New("unknown metadata version")
	}
	return &chunkMetadata{

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Delete the chunk set and re-upload the original file so the driver records the true size
  2. If writing metadata externally, compute size as an unsigned/absolute byte count
  3. Check for integer overflow in any pre-processing pipeline that sets size
Defensive patterns

Strategy: type-guard

Validate before calling

var probe struct{ Size *int64 `json:"size"` }
if json.Unmarshal(data, &probe) == nil && probe.Size != nil && *probe.Size < 0 {
    return fmt.Errorf("metadata size must be >= 0, got %d", *probe.Size)
}

Type guard

func validMetaSize(data []byte) bool {
    var probe struct{ Size *int64 `json:"size"` }
    return json.Unmarshal(data, &probe) == nil && probe.Size != nil && *probe.Size >= 0
}

Prevention

When it happens

Trigger: A metadata file with "size":-1 or any negative number — from corruption, hand editing, integer overflow in an external writer, or a buggy fork. Detected whenever metadata is parsed (listing/opening a chunked file).

Common situations: Overflow when another tool computes size as int32/int64 difference that goes negative; metadata edited to 'reset' a file; sync tools mangling numbers.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/aa72235a0a61f0b8. Report an issue: GitHub.