{"record":{"id":"cee8715e8663021d","repo":"kopia/kopia","slug":"error-appending-to-local-index-bytes","errorCode":null,"errorMessage":"error appending to local index bytes","messagePattern":"error appending to local index bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/content/committed_read_manager.go","lineNumber":202,"sourceCode":"\n\tif uint32(offset) > postamble.localIndexOffset { //nolint:gosec\n\t\treturn errors.Errorf(\"not enough data read during optimized attempt %v\", packFile)\n\t}\n\n\tpostamble.localIndexOffset -= uint32(offset) //nolint:gosec\n\n\t//nolint:gosec\n\tif uint64(postamble.localIndexOffset+postamble.localIndexLength) > uint64(payload.Length()) {\n\t\t// invalid offset/length\n\t\treturn errors.Errorf(\"unable to find valid local index in file %v - invalid offset/length\", packFile)\n\t}\n\n\tvar encryptedLocalIndexBytes gather.WriteBuffer\n\tdefer encryptedLocalIndexBytes.Close()\n\n\tif err := payload.AppendSectionTo(&encryptedLocalIndexBytes, int(postamble.localIndexOffset), int(postamble.localIndexLength)); err != nil {\n\t\t// should never happen\n\t\treturn errors.Wrap(err, \"error appending to local index bytes\")\n\t}\n\n\treturn errors.Wrap(\n\t\tsm.decryptAndVerify(encryptedLocalIndexBytes.Bytes(), postamble.localIndexIV, output),\n\t\t\"unable to decrypt local index\")\n}\n\n// +checklocks:sm.indexesLock\nfunc (sm *SharedManager) loadPackIndexesLocked(ctx context.Context) error {\n\tctx0 := contentlog.WithParams(ctx,\n\t\tlogparam.String(\"span:loadindex\", contentlog.RandomSpanID()))\n\n\tnextSleepTime := 100 * time.Millisecond //nolint:mnd\n\n\tfor i := range indexLoadAttempts {\n\t\tctx := contentlog.WithParams(ctx0,\n\t\t\tlogparam.Int(\"loadAttempt\", i))\n","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/content/committed_read_manager.go#L184-L220","documentation":"Wrapper in attemptReadPackFileLocalIndex: AppendSectionTo failed while slicing out the encrypted local-index byte range from the fetched payload — should never happen given prior bounds checks, and indicates an internal invariant violation.","triggerScenarios":"Thrown at repo/content/committed_read_manager.go:202 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the operation; if persistent, the pack data is inconsistent."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}