AlistGo/alist · error

wrong number of chunks

Error message

wrong number of chunks

What it means

The metadata's nchunks field must be between 1 and maxSafeChunkNumber (10,000,000) inclusive. Zero chunks means the file is not actually chunked (and has no business having chunk metadata), while more than 10 million chunks would exhaust file names, memory, and per-file handle limits during reassembly.

Source

Thrown at drivers/chunker/util.go:239

	}
	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{
		Version: *meta.Version,
		Size:    *meta.Size,
		NChunks: *meta.ChunkNum,

View on GitHub (pinned to 843d9dc814)

Solutions

  1. If caused by real chunking config, raise the chunk size so any single file chunks into fewer than 10,000,000 parts (with default settings this needs a file of many terabytes — check for a unit mistake)
  2. Otherwise delete the file's chunks+metadata and re-upload
  3. Verify nchunks in metadata matches the number of chunk files actually present on the remote
Defensive patterns

Strategy: validation

Validate before calling

// Before upload: ensure chunk count stays in range
nChunks := (fileSize + chunkSize - 1) / chunkSize
if nChunks < 1 || nChunks > 10000000 {
    return fmt.Errorf("chunk count %d out of range; raise chunk size", nChunks)
}

Prevention

When it happens

Trigger: A metadata file with "nchunks":0, a negative value, or > 10000000. Also triggered by genuine uploads configured with an extremely small chunk size producing more than 10M chunks. Raised during metadata parse on read.

Common situations: Hand-edited metadata; a chunk size misconfigured in bytes vs MiB so a modest file explodes into millions of tiny chunks; corrupted field values.

Related errors


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