Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify const types to support 32-bit arch #147

Merged
merged 6 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
13 changes: 6 additions & 7 deletions pkg/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import (
"fmt"
"math"

"github.com/cespare/xxhash/v2"
"go.uber.org/zap"
Expand All @@ -27,9 +26,9 @@
}

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)

Check warning on line 31 in pkg/encoder.go

View check run for this annotation

Codecov / codecov/patch

pkg/encoder.go#L31

Added line #L31 was not covered by tests
}

if len(src) == 0 {
Expand All @@ -38,9 +37,9 @@

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)

Check warning on line 42 in pkg/encoder.go

View check run for this annotation

Codecov / codecov/patch

pkg/encoder.go#L42

Added line #L42 was not covered by tests
}

entry := seekTableEntry{
Expand All @@ -56,9 +55,9 @@
}

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)

Check warning on line 60 in pkg/encoder.go

View check run for this annotation

Codecov / codecov/patch

pkg/encoder.go#L60

Added line #L60 was not covered by tests
}

seekTable := make([]byte, len(s.frameEntries)*12+9)
Expand Down
12 changes: 9 additions & 3 deletions pkg/seekable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
)

/*
Expand Down Expand Up @@ -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))
}

Expand Down
Loading