Skip to content
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
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: go

go:
- 1.5.4
- 1.6.1

sudo: false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Evan Huus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# template-repository
# go-xerial-snappy

[![Build Status](https://travis-ci.org/eapache/go-xerial-snappy.svg?branch=master)](https://travis-ci.org/eapache/go-xerial-snappy)

Xerial-compatible Snappy framing support for golang.

Packages using Xerial for snappy encoding use a framing format incompatible with
basically everything else in existence. This package wraps Go's built-in snappy
package to support it.

Apps that use this format include Apache Kafka (see
https://github.com/dpkp/kafka-python/issues/126#issuecomment-35478921 for
details).
Binary file added corpus/020dfb19a68cbcf99dc93dc1030068d4c9968ad0-2
Binary file not shown.
1 change: 1 addition & 0 deletions corpus/05979b224be0294bf350310d4ba5257c9bb815db-3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����Y
Binary file added corpus/0e64ca2823923c5efa03ff2bd6e0aa1018eeca3b-9
Binary file not shown.
Binary file added corpus/1
Binary file not shown.
Binary file added corpus/361a1c6d2a8f80780826c3d83ad391d0475c922f-4
Binary file not shown.
Binary file added corpus/4117af68228fa64339d362cf980c68ffadff96c8-12
Binary file not shown.
Binary file added corpus/4142249be82c8a617cf838eef05394ece39becd3-9
Binary file not shown.
Binary file added corpus/41ea8c7d904f1cd913b52e9ead4a96c639d76802-10
Binary file not shown.
Binary file added corpus/44083e1447694980c0ee682576e32358c9ee883f-2
Binary file not shown.
Binary file added corpus/4d6b359bd538feaa7d36c89235d07d0a443797ac-1
Binary file not shown.
1 change: 1 addition & 0 deletions corpus/521e7e67b6063a75e0eeb24b0d1dd20731d34ad8-4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�������Y
Binary file added corpus/526e6f85d1b8777f0d9f70634c9f8b77fbdccdff-7
Binary file not shown.
1 change: 1 addition & 0 deletions corpus/581b8fe7088f921567811fdf30e1f527c9f48e5e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package
Binary file added corpus/60cd10738158020f5843b43960158c3d116b3a71-11
Binary file not shown.
Binary file added corpus/652b031b4b9d601235f86ef62523e63d733b8623-3
Binary file not shown.
Binary file added corpus/684a011f6fdfc7ae9863e12381165e82d2a2e356-9
Binary file not shown.
Binary file added corpus/72e42fc8e5eaed6a8a077f420fc3bd1f9a7c0919-1
Binary file not shown.
1 change: 1 addition & 0 deletions corpus/80881d1b911b95e0203b3b0e7dc6360c35f7620f-7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
墳←��������������←�←��������������������꿽
Binary file added corpus/8484b3082d522e0a1f315db1fa1b2a5118be7cc3-8
Binary file not shown.
Binary file added corpus/9635bb09260f100bc4a2ee4e3b980fecc5b874ce-1
Binary file not shown.
Binary file added corpus/99d36b0b5b1be7151a508dd440ec725a2576c41c-1
Binary file not shown.
Binary file added corpus/9d339eddb4e2714ea319c3fb571311cb95fdb067-6
Binary file not shown.
1 change: 1 addition & 0 deletions corpus/b2419fcb7a9aef359de67cb6bd2b8a8c1f5c100f-4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����Y
Binary file added corpus/c1951b29109ec1017f63535ce3699630f46f54e1-5
Binary file not shown.
1 change: 1 addition & 0 deletions corpus/cb806bc4f67316af02d6ae677332a3b6005a18da-5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
墳��������濽
Binary file added corpus/cd7dd228703739e9252c7ea76f1c5f82ab44686a-10
Binary file not shown.
Binary file added corpus/ce3671e91907349cea04fc3f2a4b91c65b99461d-3
Binary file not shown.
1 change: 1 addition & 0 deletions corpus/ce3c6f4c31f74d72fbf74c17d14a8d29aa62059e-6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
墳←�����������������꿽
Empty file.
Binary file added corpus/e2230aa0ecaebb9b890440effa13f501a89247b2-1
Binary file not shown.
Binary file added corpus/efa11d676fb2a77afb8eac3d7ed30e330a7c2efe-11
Binary file not shown.
Binary file added corpus/f0445ac39e03978bbc8011316ac8468015ddb72c-1
Binary file not shown.
Binary file added corpus/f241da53c6bc1fe3368c55bf28db86ce15a2c784-2
Binary file not shown.
33 changes: 30 additions & 3 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
template-repository (1.0-1) unstable; urgency=medium
golang-github-eapache-go-xerial-snappy (0.0~git20180814.776d571-1) unstable; urgency=medium

* Initial release
* Team upload

-- Tsic404 <[email protected]> Sat, 28 Jan 2023 13:46:49 +0800
[ Alexandre Viau ]
* Point Vcs-* urls to salsa.debian.org.

[ Debian Janitor ]
* Bump debhelper from old 11 to 12.
* Set debhelper-compat version in Build-Depends.
* Set upstream metadata fields: Bug-Database, Bug-Submit, Repository,
Repository-Browse.
* Apply multi-arch hints.

[ Shengjing Zhu ]
* Change section to golang
* Update maintainer to [email protected]
* Bump debhelper-compat to 13
* Replace transitional package golang-snappy-go-dev
* Add Rules-Requires-Root
* Update Standards-Version to 4.6.2 (no changes)
* Add uscan watch file
* New upstream version 0.0~git20180814.776d571

-- Shengjing Zhu <[email protected]> Sun, 01 Jan 2023 17:22:02 +0800

golang-github-eapache-go-xerial-snappy (0.0~git20160609.bb955e0-1) unstable; urgency=medium

* Initial release (Closes: #840626)
Thanks to Guillem Jover for his initial work.

-- Christos Trochalakis <[email protected]> Wed, 24 Jan 2018 13:00:44 +0200
1 change: 0 additions & 1 deletion debian/compat

This file was deleted.

39 changes: 26 additions & 13 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
Source: template-repository
Section: unknown
Source: golang-github-eapache-go-xerial-snappy
Section: golang
Priority: optional
Maintainer: Tsic404 <[email protected]>
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: https://github.com/deepin-community/template-repository
#Vcs-Browser: https://salsa.debian.org/debian/deepin-community-template-repository
#Vcs-Git: https://salsa.debian.org/debian/deepin-community-template-repository.git
Maintainer: Debian Go Packaging Team <[email protected]>
Uploaders: Christos Trochalakis <[email protected]>,
Build-Depends: debhelper-compat (= 13),
dh-golang,
golang-any,
golang-github-golang-snappy-dev,
Standards-Version: 4.6.2
Homepage: https://github.com/eapache/go-xerial-snappy
Vcs-Browser: https://salsa.debian.org/go-team/packages/golang-github-eapache-go-xerial-snappy
Vcs-Git: https://salsa.debian.org/go-team/packages/golang-github-eapache-go-xerial-snappy.git
XS-Go-Import-Path: github.com/eapache/go-xerial-snappy
Rules-Requires-Root: no
Testsuite: autopkgtest-pkg-go

Package: template-repository
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: <insert up to 60 chars description>
<insert long description, indented with spaces>
Package: golang-github-eapache-go-xerial-snappy-dev
Architecture: all
Depends: golang-github-golang-snappy-dev,
${misc:Depends},
${shlibs:Depends},
Multi-Arch: foreign
Description: Xerial-compatible Snappy framing support for Go
The package wraps Go's built-in Snappy package (github.com/golang/snappy)
adding support for a Xerial compatible framing format.
.
The package was extracted from Shopify's sarama Kafka client.
44 changes: 27 additions & 17 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: template-repository
Source: https://github.com/deepin-community/template-repository
Upstream-Name: go-xerial-snappy
Source: https://github.com/eapache/go-xerial-snappy

Files: *
Copyright: 2023 Tsic404 <[email protected]>
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Copyright:
Copyright © 2016 Evan Huus
License: MIT

Files: debian/*
Copyright:
Copyright 2018 Christos Trochalakis <[email protected]>
License: MIT

License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions debian/gbp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[DEFAULT]
pristine-tar = True
6 changes: 6 additions & 0 deletions debian/gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# auto-generated, DO NOT MODIFY.
# The authoritative copy of this file lives at:
# https://salsa.debian.org/go-team/infra/pkg-go-tools/blob/master/config/gitlabciyml.go
---
include:
- https://salsa.debian.org/go-team/infra/pkg-go-tools/-/raw/master/pipeline/test-archive.yml
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/make -f

%:
dh $@
dh $@ --buildsystem=golang --with=golang
4 changes: 4 additions & 0 deletions debian/upstream/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bug-Database: https://github.com/eapache/go-xerial-snappy/issues
Bug-Submit: https://github.com/eapache/go-xerial-snappy/issues/new
Repository: https://github.com/eapache/go-xerial-snappy.git
Repository-Browse: https://github.com/eapache/go-xerial-snappy
4 changes: 4 additions & 0 deletions debian/watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version=4
opts="mode=git, pgpmode=none" \
https://github.com/eapache/go-xerial-snappy \
HEAD debian
16 changes: 16 additions & 0 deletions fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build gofuzz

package snappy

func Fuzz(data []byte) int {
decode, err := Decode(data)
if decode == nil && err == nil {
panic("nil error with nil result")
}

if err != nil {
return 0
}

return 1
}
131 changes: 131 additions & 0 deletions snappy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package snappy

import (
"bytes"
"encoding/binary"
"errors"

master "github.com/golang/snappy"
)

const (
sizeOffset = 16
sizeBytes = 4
)

var (
xerialHeader = []byte{130, 83, 78, 65, 80, 80, 89, 0}

// This is xerial version 1 and minimally compatible with version 1
xerialVersionInfo = []byte{0, 0, 0, 1, 0, 0, 0, 1}

// ErrMalformed is returned by the decoder when the xerial framing
// is malformed
ErrMalformed = errors.New("malformed xerial framing")
)

func min(x, y int) int {
if x < y {
return x
}
return y
}

// Encode encodes data as snappy with no framing header.
func Encode(src []byte) []byte {
return master.Encode(nil, src)
}

// EncodeStream *appends* to the specified 'dst' the compressed
// 'src' in xerial framing format. If 'dst' does not have enough
// capacity, then a new slice will be allocated. If 'dst' has
// non-zero length, then if *must* have been built using this function.
func EncodeStream(dst, src []byte) []byte {
if len(dst) == 0 {
dst = append(dst, xerialHeader...)
dst = append(dst, xerialVersionInfo...)
}

// Snappy encode in blocks of maximum 32KB
var (
max = len(src)
blockSize = 32 * 1024
pos = 0
chunk []byte
)

for pos < max {
newPos := min(pos + blockSize, max)
chunk = master.Encode(chunk[:cap(chunk)], src[pos:newPos])

// First encode the compressed size (big-endian)
// Put* panics if the buffer is too small, so pad 4 bytes first
origLen := len(dst)
dst = append(dst, dst[0:4]...)
binary.BigEndian.PutUint32(dst[origLen:], uint32(len(chunk)))

// And now the compressed data
dst = append(dst, chunk...)
pos = newPos
}
return dst
}

// Decode decodes snappy data whether it is traditional unframed
// or includes the xerial framing format.
func Decode(src []byte) ([]byte, error) {
return DecodeInto(nil, src)
}

// DecodeInto decodes snappy data whether it is traditional unframed
// or includes the xerial framing format into the specified `dst`.
// It is assumed that the entirety of `dst` including all capacity is available
// for use by this function. If `dst` is nil *or* insufficiently large to hold
// the decoded `src`, new space will be allocated.
func DecodeInto(dst, src []byte) ([]byte, error) {
var max = len(src)
if max < len(xerialHeader) {
return nil, ErrMalformed
}

if !bytes.Equal(src[:8], xerialHeader) {
return master.Decode(dst[:cap(dst)], src)
}

if max < sizeOffset+sizeBytes {
return nil, ErrMalformed
}

if dst == nil {
dst = make([]byte, 0, len(src))
}

dst = dst[:0]
var (
pos = sizeOffset
chunk []byte
err error
)

for pos+sizeBytes <= max {
size := int(binary.BigEndian.Uint32(src[pos : pos+sizeBytes]))
pos += sizeBytes

nextPos := pos + size
// On architectures where int is 32-bytes wide size + pos could
// overflow so we need to check the low bound as well as the
// high
if nextPos < pos || nextPos > max {
return nil, ErrMalformed
}

chunk, err = master.Decode(chunk[:cap(chunk)], src[pos:nextPos])

if err != nil {
return nil, err
}
pos = nextPos
dst = append(dst, chunk...)
}
return dst, nil
}
Loading