* chore(deps): consolidate dependency and security bumps Dependabot PRs applied: - #12878 qs 6.15.2 -> 6.16.0 (web/web-runtime) - #13013 alpine 3.24.1 -> 3.24.2 - #13061 actions/checkout -> v7.0.1 (missed instance in k8s.yml) - #13062 actions/setup-node -> v7.0.0 (missed instance in k8s.yml) - #13075 simple-git 3.36.0 -> 4.0.1 (security) - #13076 katex 0.16.45 -> 0.18.2+ (security) - #13077 dompurify 3.4.13 -> 3.4.16 (security) - #13079 go deps minor-and-patch group, 18 updates (opa 1.19.0 -> 1.21.1, otel 1.46 -> 1.47, bleve, govips, grpc-gateway, lico, tablewriter, logrus, gjson, x/exp, x/image, genproto, etc.) Skipped (already satisfied on master): #12513, #12624, #12625, #12633 Manual security bumps via pnpm.overrides (no dependabot PR existed): - axios -> 1.20.0 - smol-toml -> 1.9.0 - postcss -> 8.5.23 - postcss-selector-parser -> 7.1.6 - colord -> 2.9.4 - unhead -> 2.1.13 - markdown-it -> 14.3.1 - esbuild -> 0.28.1 - brace-expansion 5.0.11 -> 5.0.12 Not fixable: sprintf-js and elliptic have no patched version released upstream yet; left as-is. go build and pnpm install verified clean. * chore(deps): fix residual transitive vulns found by trivy trivy flagged duplicate/stale resolutions that survived the earlier override pass: dompurify (3.4.12 -> 3.4.16), qs (6.14.2 -> 6.16.0), and fast-uri (3.1.7 -> 3.1.8, CVE-2026-86472). Added/bumped pnpm.overrides accordingly. trivy fs scan of web/pnpm-lock.yaml now clean. * chore(deps): bump reva to bac0e1ee144ab853a81c6b02142032f102dd245a Pins github.com/owncloud/reva/v2 to bac0e1ee144ab853a81c6b02142032f102dd245a, pulling in its go-playground/locales and huandu/xstrings version bumps. Appends this PR to changelog/unreleased/bump-reva.md. go build ./... verified clean after go mod vendor resync. * fix(ci): revert unhead override, breaks web build * revert: keep k8s.yml actions/checkout and setup-node pinned
235 lines
6.2 KiB
Go
235 lines
6.2 KiB
Go
// Copyright (c) 2017 Couchbase, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package zap
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"io"
|
|
)
|
|
|
|
// We can safely use 0 to represent termNotEncoded since 0
|
|
// could never be a valid address for term location information.
|
|
// (stored field index is always non-empty and earlier in the
|
|
// file)
|
|
const termNotEncoded = 0
|
|
|
|
type chunkedIntCoder struct {
|
|
final []byte
|
|
chunkSize uint64
|
|
chunkBuf bytes.Buffer
|
|
chunkLens []uint64
|
|
currChunk uint64
|
|
|
|
buf []byte
|
|
|
|
bytesWritten uint64
|
|
}
|
|
|
|
// newChunkedIntCoder returns a new chunk int coder which packs data into
|
|
// chunks based on the provided chunkSize and supports up to the specified
|
|
// maxDocNum
|
|
func newChunkedIntCoder(chunkSize uint64, maxDocNum uint64) *chunkedIntCoder {
|
|
total := maxDocNum/chunkSize + 1
|
|
rv := &chunkedIntCoder{
|
|
chunkSize: chunkSize,
|
|
chunkLens: make([]uint64, total),
|
|
final: make([]byte, 0, 64),
|
|
}
|
|
|
|
return rv
|
|
}
|
|
|
|
// Reset lets you reuse this chunked int coder. buffers are reset and reused
|
|
// from previous use. you cannot change the chunk size or max doc num.
|
|
func (c *chunkedIntCoder) Reset() {
|
|
c.final = c.final[:0]
|
|
c.bytesWritten = 0
|
|
c.chunkBuf.Reset()
|
|
c.currChunk = 0
|
|
for i := range c.chunkLens {
|
|
c.chunkLens[i] = 0
|
|
}
|
|
}
|
|
|
|
// SetChunkSize changes the chunk size. It is only valid to do so
|
|
// with a new chunkedIntCoder, or immediately after calling Reset()
|
|
func (c *chunkedIntCoder) SetChunkSize(chunkSize uint64, maxDocNum uint64) {
|
|
total := int(maxDocNum/chunkSize + 1)
|
|
c.chunkSize = chunkSize
|
|
if cap(c.chunkLens) < total {
|
|
c.chunkLens = make([]uint64, total)
|
|
} else {
|
|
c.chunkLens = c.chunkLens[:total]
|
|
}
|
|
}
|
|
|
|
func (c *chunkedIntCoder) incrementBytesWritten(val uint64) {
|
|
c.bytesWritten += val
|
|
}
|
|
|
|
func (c *chunkedIntCoder) getBytesWritten() uint64 {
|
|
return c.bytesWritten
|
|
}
|
|
|
|
// Add encodes the provided integers into the correct chunk for the provided
|
|
// doc num. You MUST call Add() with increasing docNums.
|
|
func (c *chunkedIntCoder) Add(docNum uint64, vals ...uint64) error {
|
|
chunk := docNum / c.chunkSize
|
|
if chunk != c.currChunk {
|
|
// starting a new chunk
|
|
c.Close()
|
|
c.chunkBuf.Reset()
|
|
c.currChunk = chunk
|
|
}
|
|
|
|
if len(c.buf) < binary.MaxVarintLen64 {
|
|
c.buf = make([]byte, binary.MaxVarintLen64)
|
|
}
|
|
|
|
for _, val := range vals {
|
|
wb := binary.PutUvarint(c.buf, val)
|
|
_, err := c.chunkBuf.Write(c.buf[:wb])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *chunkedIntCoder) AddBytes(docNum uint64, buf []byte) error {
|
|
chunk := docNum / c.chunkSize
|
|
if chunk != c.currChunk {
|
|
// starting a new chunk
|
|
c.Close()
|
|
c.chunkBuf.Reset()
|
|
c.currChunk = chunk
|
|
}
|
|
|
|
_, err := c.chunkBuf.Write(buf)
|
|
return err
|
|
}
|
|
|
|
// Close indicates you are done calling Add() this allows the final chunk
|
|
// to be encoded.
|
|
func (c *chunkedIntCoder) Close() {
|
|
encodingBytes := c.chunkBuf.Bytes()
|
|
c.incrementBytesWritten(uint64(len(encodingBytes)))
|
|
c.chunkLens[c.currChunk] = uint64(len(encodingBytes))
|
|
c.final = append(c.final, encodingBytes...)
|
|
c.currChunk = uint64(cap(c.chunkLens)) // sentinel to detect double close
|
|
}
|
|
|
|
// Write commits all the encoded chunked integers to the provided writer.
|
|
func (c *chunkedIntCoder) Write(w io.Writer) (int, error) {
|
|
bufNeeded := binary.MaxVarintLen64 * (1 + len(c.chunkLens))
|
|
if len(c.buf) < bufNeeded {
|
|
c.buf = make([]byte, bufNeeded)
|
|
}
|
|
buf := c.buf
|
|
|
|
// process each chunk's data individually and recalculate the chunk
|
|
// lengths based on the processed data
|
|
if fw, ok := w.(*FileWriter); ok && fw != nil {
|
|
var pos int
|
|
processedBuf := make([]byte, 0)
|
|
for i := 0; i < len(c.chunkLens); i++ {
|
|
if c.chunkLens[i] == 0 {
|
|
continue
|
|
}
|
|
buf := fw.process(c.final[pos : pos+int(c.chunkLens[i])])
|
|
processedBuf = append(processedBuf, buf...)
|
|
pos += int(c.chunkLens[i])
|
|
c.chunkLens[i] = uint64(len(buf))
|
|
}
|
|
c.final = processedBuf
|
|
}
|
|
// calculate chunk offsets from chunk lengths
|
|
chunkOffsets := modifyLengthsToEndOffsets(c.chunkLens)
|
|
|
|
// write out the number of chunks & each chunk offsets
|
|
n := binary.PutUvarint(buf, uint64(len(chunkOffsets)))
|
|
for _, chunkOffset := range chunkOffsets {
|
|
n += binary.PutUvarint(buf[n:], chunkOffset)
|
|
}
|
|
|
|
tw, err := w.Write(buf[:n])
|
|
if err != nil {
|
|
return tw, err
|
|
}
|
|
|
|
// write out the data
|
|
nw, err := w.Write(c.final)
|
|
tw += nw
|
|
if err != nil {
|
|
return tw, err
|
|
}
|
|
return tw, nil
|
|
}
|
|
|
|
// writeAt commits all the encoded chunked integers to the provided writer
|
|
// and returns the starting offset, total bytes written and an error
|
|
func (c *chunkedIntCoder) writeAt(w io.Writer) (uint64, int, error) {
|
|
startOffset := uint64(termNotEncoded)
|
|
if len(c.final) <= 0 {
|
|
return startOffset, 0, nil
|
|
}
|
|
|
|
if fw, ok := w.(*FileWriter); ok && fw != nil {
|
|
startOffset = uint64(fw.Count())
|
|
}
|
|
|
|
tw, err := c.Write(w)
|
|
return startOffset, tw, err
|
|
}
|
|
|
|
func (c *chunkedIntCoder) FinalSize() int {
|
|
return len(c.final)
|
|
}
|
|
|
|
// modifyLengthsToEndOffsets converts the chunk length array
|
|
// to a chunk offset array. The readChunkBoundary
|
|
// will figure out the start and end of every chunk from
|
|
// these offsets. Starting offset of i'th index is stored
|
|
// in i-1'th position except for 0'th index and ending offset
|
|
// is stored at i'th index position.
|
|
// For 0'th element, starting position is always zero.
|
|
// eg:
|
|
// Lens -> 5 5 5 5 => 5 10 15 20
|
|
// Lens -> 0 5 0 5 => 0 5 5 10
|
|
// Lens -> 0 0 0 5 => 0 0 0 5
|
|
// Lens -> 5 0 0 0 => 5 5 5 5
|
|
// Lens -> 0 5 0 0 => 0 5 5 5
|
|
// Lens -> 0 0 5 0 => 0 0 5 5
|
|
func modifyLengthsToEndOffsets(lengths []uint64) []uint64 {
|
|
var runningOffset uint64
|
|
var index, i int
|
|
for i = 1; i <= len(lengths); i++ {
|
|
runningOffset += lengths[i-1]
|
|
lengths[index] = runningOffset
|
|
index++
|
|
}
|
|
return lengths
|
|
}
|
|
|
|
func readChunkBoundary(chunk int, offsets []uint64) (uint64, uint64) {
|
|
var start uint64
|
|
if chunk > 0 {
|
|
start = offsets[chunk-1]
|
|
}
|
|
return start, offsets[chunk]
|
|
}
|