{"record":{"id":"777872479bae945d","repo":"AlistGo/alist","slug":"wrong-number-of-chunks","errorCode":null,"errorMessage":"wrong number of chunks","messagePattern":"wrong number of chunks","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/chunker/util.go","lineNumber":239,"sourceCode":"\t}\n\tif data == nil || len(data) < 2 || data[0] != '{' || data[len(data)-1] != '}' {\n\t\treturn nil, errors.New(\"invalid json\")\n\t}\n\tvar meta metadataJSON\n\tif err := json.Unmarshal(data, &meta); err != nil {\n\t\treturn nil, err\n\t}\n\tif meta.Version == nil || meta.Size == nil || meta.ChunkNum == nil {\n\t\treturn nil, errors.New(\"missing required field\")\n\t}\n\tif *meta.Version < 1 {\n\t\treturn nil, errors.New(\"wrong version\")\n\t}\n\tif *meta.Size < 0 {\n\t\treturn nil, errors.New(\"negative file size\")\n\t}\n\tif *meta.ChunkNum < 1 || *meta.ChunkNum > maxSafeChunkNumber {\n\t\treturn nil, errors.New(\"wrong number of chunks\")\n\t}\n\tif meta.MD5 != \"\" {\n\t\tif _, err := hex.DecodeString(meta.MD5); err != nil || len(meta.MD5) != 32 {\n\t\t\treturn nil, errors.New(\"wrong md5 hash\")\n\t\t}\n\t}\n\tif meta.SHA1 != \"\" {\n\t\tif _, err := hex.DecodeString(meta.SHA1); err != nil || len(meta.SHA1) != 40 {\n\t\t\treturn nil, errors.New(\"wrong sha1 hash\")\n\t\t}\n\t}\n\tif *meta.Version > chunkerMetadataVerion {\n\t\treturn nil, errors.New(\"unknown metadata version\")\n\t}\n\treturn &chunkMetadata{\n\t\tVersion: *meta.Version,\n\t\tSize:    *meta.Size,\n\t\tNChunks: *meta.ChunkNum,","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/chunker/util.go#L221-L257","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-edited metadata; a chunk size misconfigured in bytes vs MiB so a modest file explodes into millions of tiny chunks; corrupted field values.","solutions":["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)","Otherwise delete the file's chunks+metadata and re-upload","Verify nchunks in metadata matches the number of chunk files actually present on the remote"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before upload: ensure chunk count stays in range\nnChunks := (fileSize + chunkSize - 1) / chunkSize\nif nChunks < 1 || nChunks > 10000000 {\n    return fmt.Errorf(\"chunk count %d out of range; raise chunk size\", nChunks)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanity-check chunk size units (bytes vs KiB/MiB) before large uploads","For very large files, compute expected chunk count and raise chunk size accordingly"],"tags":["chunker","metadata","limits","configuration"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}