1
0
Fork 0
forked from forgejo/forgejo
This commit is contained in:
techknowlogick 2021-02-28 18:08:33 -05:00 committed by GitHub
parent 030646eea4
commit 47f6a4ec3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
947 changed files with 26119 additions and 7062 deletions

View file

@ -31,4 +31,6 @@ Temporary Items
# End of https://www.gitignore.io/api/macos
cmd/*/*exe
.idea
.idea
fuzz/*.zip

View file

@ -1,19 +0,0 @@
language: go
env:
- GO111MODULE=off
go:
- 1.13.x
- 1.14.x
matrix:
fast_finish: true
sudo: false
script:
- go test -v -cpu=2
- go test -v -cpu=2 -race
- go test -v -cpu=2 -tags noasm
- go test -v -cpu=2 -race -tags noasm

View file

@ -1,7 +1,7 @@
# lz4 : LZ4 compression in pure Go
[![GoDoc](https://godoc.org/github.com/pierrec/lz4?status.svg)](https://godoc.org/github.com/pierrec/lz4)
[![Build Status](https://travis-ci.org/pierrec/lz4.svg?branch=master)](https://travis-ci.org/pierrec/lz4)
[![Go Reference](https://pkg.go.dev/badge/github.com/pierrec/lz4/v4.svg)](https://pkg.go.dev/github.com/pierrec/lz4/v4)
[![CI](https://github.com/pierrec/lz4/workflows/ci/badge.svg)](https://github.com/pierrec/lz4/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/pierrec/lz4)](https://goreportcard.com/report/github.com/pierrec/lz4)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/pierrec/lz4.svg?style=social)](https://github.com/pierrec/lz4/tags)
@ -15,13 +15,13 @@ The implementation is based on the reference C [one](https://github.com/lz4/lz4)
Assuming you have the go toolchain installed:
```
go get github.com/pierrec/lz4
go get github.com/pierrec/lz4/v4
```
There is a command line interface tool to compress and decompress LZ4 files.
```
go install github.com/pierrec/lz4/cmd/lz4c
go install github.com/pierrec/lz4/v4/cmd/lz4c
```
Usage

View file

@ -1,3 +0,0 @@
github.com/pierrec/lz4 v1.0.1 h1:w6GMGWSsCI04fTM8wQRdnW74MuJISakuUU0onU0TYB4=
github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A=
github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=

View file

@ -140,25 +140,22 @@ readMatchlenLoop:
BEQ readMatchlenLoop
readMatchlenDone:
ADD minMatch, len
// Bounds check dst+len and match = dst-offset.
// Bounds check dst+len+minMatch and match = dst-offset.
ADD dst, len, tmp1
ADD minMatch, tmp1
CMP dstend, tmp1
//BHI shortDst // Uncomment for distinct error codes.
SUB offset, dst, match
CMP.LS match, dstorig
BHI corrupt
// If the offset is at least four (len is, because of minMatch),
// do a four-way unrolled byte copy loop. Using MOVD instead of four
// byte loads is much faster, but to remain portable we'd have to
// align match first, which in turn is too expensive.
CMP $4, offset
BLO copyMatch
SUB $4, len
// Since len+minMatch is at least four, we can do a 4× unrolled
// byte copy loop. Using MOVW instead of four byte loads is faster,
// but to remain portable we'd have to align match first, which is
// too expensive. By alternating loads and stores, we also handle
// the case offset < 4.
copyMatch4:
SUB.S $4, len
MOVBU.P 4(match), tmp1
MOVB.P tmp1, 4(dst)
MOVBU -3(match), tmp2
@ -167,7 +164,6 @@ copyMatch4:
MOVB tmp3, -2(dst)
MOVBU -1(match), tmp1
MOVB tmp1, -1(dst)
SUB.S $4, len
BPL copyMatch4
// Restore len, which is now negative.
@ -175,7 +171,7 @@ copyMatch4:
BEQ copyMatchDone
copyMatch:
// Simple byte-at-a-time copy.
// Finish with a byte-at-a-time copy.
SUB.S $1, len
MOVBU.P 1(match), tmp2
MOVB.P tmp2, 1(dst)

View file

@ -2,7 +2,13 @@
package lz4block
import "encoding/binary"
func decodeBlock(dst, src []byte) (ret int) {
// Restrict capacities so we don't read or write out of bounds.
dst = dst[:len(dst):len(dst)]
src = src[:len(src):len(src)]
const hasError = -2
defer func() {
if recover() != nil {
@ -32,7 +38,7 @@ func decodeBlock(dst, src []byte) (ret int) {
// if the match length (4..18) fits within the literals, then copy
// all 18 bytes, even if not all are part of the literals.
mLen += 4
if offset := uint(src[si]) | uint(src[si+1])<<8; mLen <= offset {
if offset := u16(src[si:]); mLen <= offset {
i := di - offset
end := i + 18
if end > uint(len(dst)) {
@ -66,7 +72,7 @@ func decodeBlock(dst, src []byte) (ret int) {
return hasError
}
offset := uint(src[si]) | uint(src[si+1])<<8
offset := u16(src[si:])
if offset == 0 {
return hasError
}
@ -98,3 +104,5 @@ func decodeBlock(dst, src []byte) (ret int) {
di += uint(copy(dst[di:di+mLen], expanded[:mLen]))
}
}
func u16(p []byte) uint { return uint(binary.LittleEndian.Uint16(p)) }

View file

@ -67,8 +67,9 @@ func (b *Blocks) close(f *Frame, num int) error {
return err
}
if b.Blocks == nil {
// Not initialized yet.
return nil
err := b.err
b.err = nil
return err
}
c := make(chan *FrameDataBlock)
b.Blocks <- c
@ -114,15 +115,18 @@ func (b *Blocks) initR(f *Frame, num int, src io.Reader) (chan []byte, error) {
block := NewFrameDataBlock(f)
cumx, err = block.Read(f, src, 0)
if err != nil {
block.Close(f)
break
}
// Recheck for an error as reading may be slow and uncompressing is expensive.
if b.ErrorR() != nil {
block.Close(f)
break
}
c := make(chan []byte)
blocks <- c
go func() {
defer block.Close(f)
data, err := block.Uncompress(f, size.Get(), false)
if err != nil {
b.closeR(err)