diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0836ca9..5eee8b7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -27,9 +27,32 @@ jobs: working-directory: ./${{ matrix.dir }} run: | go get . + - name: go work + run: | + if [ "${{ matrix.dir }}" == "pkg" ]; then + echo "Skipping go workspace for ${{ matrix.dir }}" + rm -f go.work* + exit 0 + fi + go work init + go work use pkg + go work use ${{ matrix.dir }} - name: Build (${{ matrix.dir }}) working-directory: ./${{ matrix.dir }} - run: go build -v ./... + run: | + for OSARCH in $(go tool dist list); do + case $OSARCH in + freebsd*|darwin*|linux*|windows*|wasip*) ;; + *) continue ;; + esac + case $OSARCH in + *arm64|*arm|*amd64|*386|*riscv64|*wasm) ;; + *) continue ;; + esac + IFS="/" read -r OS ARCH <<< "$OSARCH" + echo "Building for $OS $ARCH" + GOOS=$OS GOARCH=$ARCH go build ./... + done - name: Test (${{ matrix.dir }}) working-directory: ./${{ matrix.dir }} run: go test -v ./... diff --git a/pkg/encoder.go b/pkg/encoder.go index 89ad4ef..7b343bd 100644 --- a/pkg/encoder.go +++ b/pkg/encoder.go @@ -2,7 +2,6 @@ package seekable import ( "fmt" - "math" "github.com/cespare/xxhash/v2" "go.uber.org/zap" @@ -27,9 +26,9 @@ func NewEncoder(encoder ZSTDEncoder, opts ...wOption) (Encoder, error) { } func (s *writerImpl) Encode(src []byte) ([]byte, error) { - if len(src) > math.MaxUint32 { + if int64(len(src)) > maxChunkSize { return nil, fmt.Errorf("chunk size too big for seekable format: %d > %d", - len(src), math.MaxUint32) + len(src), maxChunkSize) } if len(src) == 0 { @@ -38,9 +37,9 @@ func (s *writerImpl) Encode(src []byte) ([]byte, error) { dst := s.enc.EncodeAll(src, nil) - if len(dst) > math.MaxUint32 { + if int64(len(dst)) > maxChunkSize { return nil, fmt.Errorf("result size too big for seekable format: %d > %d", - len(src), math.MaxUint32) + len(src), maxChunkSize) } entry := seekTableEntry{ @@ -56,9 +55,9 @@ func (s *writerImpl) Encode(src []byte) ([]byte, error) { } func (s *writerImpl) EndStream() ([]byte, error) { - if len(s.frameEntries) > math.MaxUint32 { + if int64(len(s.frameEntries)) > maxNumberOfFrames { return nil, fmt.Errorf("number of frames for seekable format: %d > %d", - len(s.frameEntries), math.MaxUint32) + len(s.frameEntries), maxNumberOfFrames) } seekTable := make([]byte, len(s.frameEntries)*12+9) diff --git a/pkg/seekable.go b/pkg/seekable.go index b5c6658..795a5e9 100644 --- a/pkg/seekable.go +++ b/pkg/seekable.go @@ -36,9 +36,9 @@ const ( https://github.com/facebook/zstd/blob/dev/contrib/seekable_format/zstd_seekable_compression_format.md */ - skippableFrameMagic = 0x184D2A50 + skippableFrameMagic uint32 = 0x184D2A50 - seekableMagicNumber = 0x8F92EAB1 + seekableMagicNumber uint32 = 0x8F92EAB1 seekTableFooterOffset = 9 @@ -49,6 +49,12 @@ const ( maxDecoderFrameSize = 128 << 20 seekableTag = 0xE + + // maximum size of a single frame + maxChunkSize int64 = math.MaxUint32 + + // maximum number of frames in a seekable stream + maxNumberOfFrames int64 = math.MaxUint32 ) /* @@ -234,7 +240,7 @@ func createSkippableFrame(tag uint32, payload []byte) ([]byte, error) { return nil, fmt.Errorf("requested tag (%d) > 0xf", tag) } - if len(payload) > math.MaxUint32 { + if int64(len(payload)) > maxChunkSize { return nil, fmt.Errorf("requested skippable frame size (%d) > max uint32", len(payload)) }