kopia/kopia · error

error appending to local index bytes

Error message

error appending to local index bytes

What it means

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.

Solutions

  1. Retry the operation; if persistent, the pack data is inconsistent.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at repo/content/committed_read_manager.go:202 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/cee8715e8663021d. Report an issue: GitHub.

Appendix: source

Thrown at repo/content/committed_read_manager.go:202

	if uint32(offset) > postamble.localIndexOffset { //nolint:gosec
		return errors.Errorf("not enough data read during optimized attempt %v", packFile)
	}

	postamble.localIndexOffset -= uint32(offset) //nolint:gosec

	//nolint:gosec
	if uint64(postamble.localIndexOffset+postamble.localIndexLength) > uint64(payload.Length()) {
		// invalid offset/length
		return errors.Errorf("unable to find valid local index in file %v - invalid offset/length", packFile)
	}

	var encryptedLocalIndexBytes gather.WriteBuffer
	defer encryptedLocalIndexBytes.Close()

	if err := payload.AppendSectionTo(&encryptedLocalIndexBytes, int(postamble.localIndexOffset), int(postamble.localIndexLength)); err != nil {
		// should never happen
		return errors.Wrap(err, "error appending to local index bytes")
	}

	return errors.Wrap(
		sm.decryptAndVerify(encryptedLocalIndexBytes.Bytes(), postamble.localIndexIV, output),
		"unable to decrypt local index")
}

// +checklocks:sm.indexesLock
func (sm *SharedManager) loadPackIndexesLocked(ctx context.Context) error {
	ctx0 := contentlog.WithParams(ctx,
		logparam.String("span:loadindex", contentlog.RandomSpanID()))

	nextSleepTime := 100 * time.Millisecond //nolint:mnd

	for i := range indexLoadAttempts {
		ctx := contentlog.WithParams(ctx0,
			logparam.Int("loadAttempt", i))

View on GitHub (pinned to 82495e54b5)