Skip to content

Commit

Permalink
Merge pull request #147 from wolfogre/bugfix/386_arch
Browse files Browse the repository at this point in the history
Specify const types to support 32-bit arch
  • Loading branch information
SaveTheRbtz authored Aug 2, 2024
2 parents 54f6705 + 301c94b commit 42610f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
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 @@ package seekable

import (
"fmt"
"math"

"github.com/cespare/xxhash/v2"
"go.uber.org/zap"
Expand All @@ -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 {
Expand All @@ -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{
Expand All @@ -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)
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

0 comments on commit 42610f0

Please sign in to comment.