Repository: dolthub/dolt
File: go/store/nbs/archive_reader.go (Go)

Code before:
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to read byte spans: %w", err)
	}

	prefixSpan := footer.indexPrefixSpan()
	prefixRdr := newSectionReader(ctx, reader, int64(prefixSpan.offset), int64(prefixSpan.length), stats)
	prefixes, err := q.AcquireQuotaUint64s(ctx, int(footer.chunkCount))
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to allocate prefixes uint32 slice: %w", err)
	}
	bytesSoFar += len(prefixes) * 8
	err = binary.Read(prefixRdr, binary.BigEndian, prefixes[:])
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to read prefixes: %w", err)
	}

	chunkRefSpan := footer.indexChunkRefSpan()
	chunkRdr := newSectionReader(ctx, reader, int64(chunkRefSpan.offset), int64(chunkRefSpan.length), stats)
	chnks, err := q.AcquireQuotaUint32s(ctx, int(footer.chunkCount)*2)
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to allocate chunks uint32 slice: %w", err)
	}
	bytesSoFar += len(chnks) * 4
	err = binary.Read(chunkRdr, binary.BigEndian, chnks[:])
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to read chunk references: %w", err)
	}

	suffixSpan := footer.indexSuffixSpan()
	sufRdr := newSectionReader(ctx, reader, int64(suffixSpan.offset), int64(suffixSpan.length), stats)
	suffixes, err := q.AcquireQuotaBytes(ctx, int(suffixSpan.length))
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to allocate suffixes byte slice: %w", err)
	}
	bytesSoFar += len(suffixes)
	_, err = io.ReadFull(sufRdr, suffixes)
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, err
	}

	ret := &inMemoryArchiveIndexReader{
		prefixes:  prefixes,
		spanIndex: byteSpans,
		chunkRefs: chnks,
		suffixes:  suffixes,

Review comment (suggestion):
```suggestion
	bytesSoFar += len(chnks) * uint32Size
```

Code after:
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to read byte spans: %w", err)
	}

	prefixSpan := footer.indexPrefixSpan()
	prefixRdr := newSectionReader(ctx, reader, int64(prefixSpan.offset), int64(prefixSpan.length), stats)
	prefixes, err := q.AcquireQuotaUint64s(ctx, int(footer.chunkCount))
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to allocate prefixes uint32 slice: %w", err)
	}
	bytesSoFar += len(prefixes) * uint64Size
	err = binary.Read(prefixRdr, binary.BigEndian, prefixes[:])
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to read prefixes: %w", err)
	}

	chunkRefSpan := footer.indexChunkRefSpan()
	chunkRdr := newSectionReader(ctx, reader, int64(chunkRefSpan.offset), int64(chunkRefSpan.length), stats)
	chnks, err := q.AcquireQuotaUint32s(ctx, int(footer.chunkCount)*2)
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to allocate chunks uint32 slice: %w", err)
	}
	bytesSoFar += len(chnks) * uint32Size
	err = binary.Read(chunkRdr, binary.BigEndian, chnks[:])
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to read chunk references: %w", err)
	}

	suffixSpan := footer.indexSuffixSpan()
	sufRdr := newSectionReader(ctx, reader, int64(suffixSpan.offset), int64(suffixSpan.length), stats)
	suffixes, err := q.AcquireQuotaBytes(ctx, int(suffixSpan.length))
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, fmt.Errorf("Failed to allocate suffixes byte slice: %w", err)
	}
	bytesSoFar += len(suffixes)
	_, err = io.ReadFull(sufRdr, suffixes)
	if err != nil {
		q.ReleaseQuotaBytes(bytesSoFar)
		return nil, err
	}

	ret := &inMemoryArchiveIndexReader{
		prefixes:  prefixes,
		spanIndex: byteSpans,
		chunkRefs: chnks,
		suffixes:  suffixes,