{"record":{"id":"c03df6bb40bc57df","repo":"AlistGo/alist","slug":"doubao-new-v3-fallback-payload-out-of-range-seq","errorCode":null,"errorMessage":"[doubao_new] v3 fallback payload out of range: seq=%d offset=%d size=%d total=%d","messagePattern":"\\[doubao_new\\] v3 fallback payload out of range: seq=(.+?) offset=(.+?) size=(.+?) total=(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/doubao_new/util.go","lineNumber":793,"sourceCode":"\t\tmsg := fmt.Sprintf(\"[doubao_new] decode response failed (status: %s, content-type: %s, body: %s): %v\",\n\t\t\tres.Status(),\n\t\t\tres.Header().Get(\"Content-Type\"),\n\t\t\tstring(body),\n\t\t\terr,\n\t\t)\n\t\treturn UploadMergeData{}, fmt.Errorf(msg)\n\t}\n\tif resp.Code != 0 {\n\t\tif res != nil && res.StatusCode() == http.StatusBadRequest && resp.Code == 2 {\n\t\t\tsuccess := make([]int, 0, len(seqList))\n\t\t\toffset := 0\n\t\t\tfor i, seq := range seqList {\n\t\t\t\tsize := sizeList[i]\n\t\t\t\tif size <= 0 {\n\t\t\t\t\treturn UploadMergeData{SuccessSeqList: success}, fmt.Errorf(\"[doubao_new] v3 fallback invalid size: seq=%d size=%d\", seq, size)\n\t\t\t\t}\n\t\t\t\tif offset+int(size) > len(data) {\n\t\t\t\t\treturn UploadMergeData{SuccessSeqList: success}, fmt.Errorf(\"[doubao_new] v3 fallback payload out of range: seq=%d offset=%d size=%d total=%d\", seq, offset, size, len(data))\n\t\t\t\t}\n\t\t\t\tpayload := data[offset : offset+int(size)]\n\t\t\t\tblock := UploadBlockNeed{\n\t\t\t\t\tSeq:      seq,\n\t\t\t\t\tSize:     size,\n\t\t\t\t\tChecksum: checksumList[i],\n\t\t\t\t}\n\t\t\t\tif err := d.uploadBlockV3(ctx, uploadID, block, payload); err != nil {\n\t\t\t\t\treturn UploadMergeData{SuccessSeqList: success}, err\n\t\t\t\t}\n\t\t\t\tsuccess = append(success, seq)\n\t\t\t\toffset += int(size)\n\t\t\t}\n\t\t\treturn UploadMergeData{SuccessSeqList: success}, nil\n\t\t}\n\t\terrMsg := resp.Msg\n\t\tif errMsg == \"\" {\n\t\t\terrMsg = resp.Message","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/doubao_new/util.go#L775-L811","documentation":"Second guard in the v3 fallback loop: the cumulative offset plus the block's size would slice past the end of data, meaning sum(sizeList) > len(data). The concatenated payloads no longer match the declared sizes, so re-upload cannot proceed.","triggerScenarios":"mergeUploadBlocks is invoked with sizeList that sums to more than the actual data buffer length — e.g., data was truncated after sizes were computed, sizes come from a different file version, or a caller passes mismatched parallel slices. Reached only after a 400/code-2 merge rejection triggers the fallback.","commonSituations":"File modified during upload (size changed between hashing and reading); tmpFile shorter than expected; bug in group accumulation where groupSizes retains entries from a previous group.","solutions":["Restart the upload end-to-end with a fresh upload_id; partial state is inconsistent.","Add a pre-check where data is assembled: fail if int64(len(data)) != sum(groupSizes) (the flushGroup check exists but only compares against groupExpectSum — make sure groupExpectSum is derived from the same sizeList).","Ensure the source file is immutable for the duration of the upload (copy-on-write snapshot or lock)."],"exampleFix":"// before\npayload := data[offset : offset+int(size)]\n\n// after\ntotal := int64(0)\nfor _, s := range sizeList { total += s }\nif total != int64(len(data)) {\n    return UploadMergeData{}, fmt.Errorf(\"[doubao_new] sizes/data mismatch: sum=%d len=%d\", total, len(data))\n}","handlingStrategy":"validation","validationCode":"total := int64(0)\nfor _, s := range sizeList { total += s }\nif total != int64(len(data)) {\n    return fmt.Errorf(\"sizes/data mismatch: sum=%d len=%d\", total, len(data))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive groupExpectSum and sizeList from the same slice so they cannot diverge.","Keep the source file immutable during upload (snapshot/lock)."],"tags":["doubao","upload","fallback","data-integrity"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}