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

@ -1,4 +1,4 @@
Copyright (c) 2014-2020 Ulrich Kunitz
Copyright (c) 2014-2021 Ulrich Kunitz
All rights reserved.
Redistribution and use in source and binary forms, with or without

10
vendor/github.com/ulikunitz/xz/SECURITY.md generated vendored Normal file
View file

@ -0,0 +1,10 @@
# Security Policy
## Supported Versions
Currently the last minor version v0.5.x is supported.
## Reporting a Vulnerability
Report a vulnerability by creating a Github issue at
<https://github.com/ulikunitz/xz/issues>. Expect a response in a week.

View file

@ -8,19 +8,17 @@
1. Review encoder and check for lzma improvements under xz.
2. Fix binary tree matcher.
3. Compare compression ratio with xz tool using comparable parameters
and optimize parameters
4. Do some optimizations
- rename operation action and make it a simple type of size 8
- make maxMatches, wordSize parameters
- stop searching after a certain length is found (parameter sweetLen)
3. Compare compression ratio with xz tool using comparable parameters and optimize parameters
4. rename operation action and make it a simple type of size 8
5. make maxMatches, wordSize parameters
6. stop searching after a certain length is found (parameter sweetLen)
## Release v0.7
1. Optimize code
2. Do statistical analysis to get linear presets.
3. Test sync.Pool compatability for xz and lzma Writer and Reader
3. Fuzz optimized code.
4. Fuzz optimized code.
## Release v0.8
@ -44,53 +42,81 @@
## Package lzma
### Release v0.6
- Rewrite Encoder into a simple greedy one-op-at-a-time encoder
including
+ simple scan at the dictionary head for the same byte
+ use the killer byte (requiring matches to get longer, the first
test should be the byte that would make the match longer)
### v0.6
* Rewrite Encoder into a simple greedy one-op-at-a-time encoder including
* simple scan at the dictionary head for the same byte
* use the killer byte (requiring matches to get longer, the first test should be the byte that would make the match longer)
## Optimizations
- There may be a lot of false sharing in lzma.State; check whether this
can be improved by reorganizing the internal structure of it.
- Check whether batching encoding and decoding improves speed.
* There may be a lot of false sharing in lzma. State; check whether this can be improved by reorganizing the internal structure of it.
* Check whether batching encoding and decoding improves speed.
### DAG optimizations
- Use full buffer to create minimal bit-length above range encoder.
- Might be too slow (see v0.4)
* Use full buffer to create minimal bit-length above range encoder.
* Might be too slow (see v0.4)
### Different match finders
- hashes with 2, 3 characters additional to 4 characters
- binary trees with 2-7 characters (uint64 as key, use uint32 as
* hashes with 2, 3 characters additional to 4 characters
* binary trees with 2-7 characters (uint64 as key, use uint32 as
pointers into a an array)
- rb-trees with 2-7 characters (uint64 as key, use uint32 as pointers
* rb-trees with 2-7 characters (uint64 as key, use uint32 as pointers
into an array with bit-steeling for the colors)
## Release Procedure
- execute goch -l for all packages; probably with lower param like 0.5.
- check orthography with gospell
- Write release notes in doc/relnotes.
- Update README.md
- xb copyright . in xz directory to ensure all new files have Copyright
header
- VERSION=<version> go generate github.com/ulikunitz/xz/... to update
version files
- Execute test for Linux/amd64, Linux/x86 and Windows/amd64.
- Update TODO.md - write short log entry
- git checkout master && git merge dev
- git tag -a <version>
- git push
* execute goch -l for all packages; probably with lower param like 0.5.
* check orthography with gospell
* Write release notes in doc/relnotes.
* Update README.md
* xb copyright . in xz directory to ensure all new files have Copyright header
* `VERSION=<version> go generate github.com/ulikunitz/xz/...` to update version files
* Execute test for Linux/amd64, Linux/x86 and Windows/amd64.
* Update TODO.md - write short log entry
* `git checkout master && git merge dev`
* `git tag -a <version>`
* `git push`
## Log
## 2020-08-19
### 2021-02-02
Mituo Heijo has fuzzed xz and found a bug in the function readIndexBody. The
function allocated a slice of records immediately after reading the value
without further checks. Since the number has been too large the make function
did panic. The fix is to check the number against the expected number of records
before allocating the records.
### 2020-12-17
Release v0.5.9 fixes warnings, a typo and adds SECURITY.md.
One fix is interesting.
```go
const (
a byte = 0x1
b = 0x2
)
```
The constants a and b don't have the same type. Correct is
```go
const (
a byte = 0x1
b byte = 0x2
)
```
### 2020-08-19
Release v0.5.8 fixes issue
[issue #35](https://github.com/ulikunitz/xz/issues/35).
@ -208,8 +234,8 @@ MININT.
### 2015-06-04
It has been a productive day. I improved the interface of lzma.Reader
and lzma.Writer and fixed the error handling.
It has been a productive day. I improved the interface of lzma. Reader
and lzma. Writer and fixed the error handling.
### 2015-06-01
@ -260,7 +286,7 @@ needed anymore.
However I will implement a ReaderState and WriterState type to use
static typing to ensure the right State object is combined with the
right lzbase.Reader and lzbase.Writer.
right lzbase. Reader and lzbase. Writer.
As a start I have implemented ReaderState and WriterState to ensure
that the state for reading is only used by readers and WriterState only
@ -282,11 +308,11 @@ old lzma package has been completely removed.
### 2015-04-05
Implemented lzma.Reader and tested it.
Implemented lzma. Reader and tested it.
### 2015-04-04
Implemented baseReader by adapting code form lzma.Reader.
Implemented baseReader by adapting code form lzma. Reader.
### 2015-04-03
@ -302,7 +328,7 @@ However in Francesco Campoy's presentation "Go for Javaneros
(Javaïstes?)" is the the idea that using an embedded field E, all the
methods of E will be defined on T. If E is an interface T satisfies E.
https://talks.golang.org/2014/go4java.slide#51
<https://talks.golang.org/2014/go4java.slide#51>
I have never used this, but it seems to be a cool idea.
@ -327,11 +353,11 @@ and the opCodec.
1. Implemented simple lzmago tool
2. Tested tool against large 4.4G file
- compression worked correctly; tested decompression with lzma
- decompression hits a full buffer condition
* compression worked correctly; tested decompression with lzma
* decompression hits a full buffer condition
3. Fixed a bug in the compressor and wrote a test for it
4. Executed full cycle for 4.4 GB file; performance can be improved ;-)
### 2015-01-11
- Release v0.2 because of the working LZMA encoder and decoder
* Release v0.2 because of the working LZMA encoder and decoder

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -47,9 +47,9 @@ const HeaderLen = 12
// Constants for the checksum methods supported by xz.
const (
None byte = 0x0
CRC32 = 0x1
CRC64 = 0x4
SHA256 = 0xa
CRC32 byte = 0x1
CRC64 byte = 0x4
SHA256 byte = 0xa
)
// errInvalidFlags indicates that flags are invalid.
@ -569,22 +569,6 @@ func readFilters(r io.Reader, count int) (filters []filter, err error) {
return []filter{f}, err
}
// writeFilters writes the filters.
func writeFilters(w io.Writer, filters []filter) (n int, err error) {
for _, f := range filters {
p, err := f.MarshalBinary()
if err != nil {
return n, err
}
k, err := w.Write(p)
n += k
if err != nil {
return n, err
}
}
return n, nil
}
/*** Index ***/
// record describes a block in the xz file index.
@ -678,7 +662,7 @@ func writeIndex(w io.Writer, index []record) (n int64, err error) {
// readIndexBody reads the index from the reader. It assumes that the
// index indicator has already been read.
func readIndexBody(r io.Reader) (records []record, n int64, err error) {
func readIndexBody(r io.Reader, expectedRecordLen int) (records []record, n int64, err error) {
crc := crc32.NewIEEE()
// index indicator
crc.Write([]byte{0})
@ -695,6 +679,11 @@ func readIndexBody(r io.Reader) (records []record, n int64, err error) {
if recLen < 0 || uint64(recLen) != u {
return nil, n, errors.New("xz: record number overflow")
}
if recLen != expectedRecordLen {
return nil, n, fmt.Errorf(
"xz: index length is %d; want %d",
recLen, expectedRecordLen)
}
// list of records
records = make([]record, recLen)

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,14 +1,11 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lzma
import (
"bufio"
"errors"
"fmt"
"io"
"unicode"
)
@ -349,6 +346,7 @@ func dumpX(x uint32) string {
return string(a)
}
/*
// dumpNode writes a representation of the node v into the io.Writer.
func (t *binTree) dumpNode(w io.Writer, v uint32, indent int) {
if v == null {
@ -377,6 +375,7 @@ func (t *binTree) dump(w io.Writer) error {
t.dumpNode(bw, t.root, 0)
return bw.Flush()
}
*/
func (t *binTree) distance(v uint32) int {
dist := int(t.front) - int(v)

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -18,6 +18,7 @@ var ntz32Table = [32]int8{
30, 17, 8, 14, 29, 13, 28, 27,
}
/*
// ntz32 computes the number of trailing zeros for an unsigned 32-bit integer.
func ntz32(x uint32) int {
if x == 0 {
@ -26,6 +27,7 @@ func ntz32(x uint32) int {
x = (x & -x) * ntz32Const
return int(ntz32Table[x>>27])
}
*/
// nlz32 computes the number of leading zeros for an unsigned 32-bit integer.
func nlz32(x uint32) int {

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -200,7 +200,7 @@ func (d *decoder) decompress() error {
op, err := d.readOp()
switch err {
case nil:
break
// break
case errEOS:
d.eos = true
if !d.rd.possiblyAtEnd() {

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -126,10 +126,3 @@ func (d *decoderDict) Available() int { return d.buf.Available() }
// Read reads data from the buffer contained in the decoder dictionary.
func (d *decoderDict) Read(p []byte) (n int, err error) { return d.buf.Read(p) }
// Buffered returns the number of bytes currently buffered in the
// decoder dictionary.
func (d *decoderDict) buffered() int { return d.buf.Buffered() }
// Peek gets data from the buffer without advancing the rear index.
func (d *decoderDict) peek(p []byte) (n int, err error) { return d.buf.Peek(p) }

View file

@ -1,24 +1,13 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lzma
import "fmt"
// directCodec allows the encoding and decoding of values with a fixed number
// of bits. The number of bits must be in the range [1,32].
type directCodec byte
// makeDirectCodec creates a directCodec. The function panics if the number of
// bits is not in the range [1,32].
func makeDirectCodec(bits int) directCodec {
if !(1 <= bits && bits <= 32) {
panic(fmt.Errorf("bits=%d out of range", bits))
}
return directCodec(bits)
}
// Bits returns the number of bits supported by this codec.
func (dc directCodec) Bits() int {
return int(dc)

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -20,8 +20,6 @@ const (
posSlotBits = 6
// number of align bits
alignBits = 4
// maximum position slot
maxPosSlot = 63
)
// distCodec provides encoding and decoding of distance values.
@ -45,20 +43,6 @@ func (dc *distCodec) deepcopy(src *distCodec) {
dc.alignCodec.deepcopy(&src.alignCodec)
}
// distBits returns the number of bits required to encode dist.
func distBits(dist uint32) int {
if dist < startPosModel {
return 6
}
// slot s > 3, dist d
// s = 2(bits(d)-1) + bit(d, bits(d)-2)
// s>>1 = bits(d)-1
// bits(d) = 32-nlz32(d)
// s>>1=31-nlz32(d)
// n = 5 + (s>>1) = 36 - nlz32(d)
return 36 - nlz32(dist)
}
// newDistCodec creates a new distance codec.
func (dc *distCodec) init() {
for i := range dc.posSlotCodecs {

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -19,7 +19,7 @@ type matcher interface {
}
// encoderDict provides the dictionary of the encoder. It includes an
// addtional buffer atop of the actual dictionary.
// additional buffer atop of the actual dictionary.
type encoderDict struct {
buf buffer
m matcher

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -264,7 +264,7 @@ type chunkState byte
// state
const (
start chunkState = 'S'
stop = 'T'
stop chunkState = 'T'
)
// errors for the chunk state handling

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -56,19 +56,6 @@ func (lc *lengthCodec) init() {
lc.high = makeTreeCodec(8)
}
// lBits gives the number of bits used for the encoding of the l value
// provided to the range encoder.
func lBits(l uint32) int {
switch {
case l < 8:
return 4
case l < 16:
return 5
default:
return 10
}
}
// Encode encodes the length offset. The length offset l can be compute by
// subtracting minMatchLen (2) from the actual length.
//

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -123,10 +123,3 @@ const (
minLP = 0
maxLP = 4
)
// minState and maxState define a range for the state values stored in
// the State values.
const (
minState = 0
maxState = 11
)

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,11 +1,10 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lzma
import (
"errors"
"fmt"
"unicode"
)
@ -24,30 +23,6 @@ type match struct {
n int
}
// verify checks whether the match is valid. If that is not the case an
// error is returned.
func (m match) verify() error {
if !(minDistance <= m.distance && m.distance <= maxDistance) {
return errors.New("distance out of range")
}
if !(1 <= m.n && m.n <= maxMatchLen) {
return errors.New("length out of range")
}
return nil
}
// l return the l-value for the match, which is the difference of length
// n and 2.
func (m match) l() uint32 {
return uint32(m.n - minMatchLen)
}
// dist returns the dist value for the match, which is one less of the
// distance stored in the match.
func (m match) dist() uint32 {
return uint32(m.distance - minDistance)
}
// Len returns the number of bytes matched.
func (m match) Len() int {
return m.n

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -131,32 +131,6 @@ type rangeDecoder struct {
code uint32
}
// init initializes the range decoder, by reading from the byte reader.
func (d *rangeDecoder) init() error {
d.nrange = 0xffffffff
d.code = 0
b, err := d.br.ReadByte()
if err != nil {
return err
}
if b != 0 {
return errors.New("newRangeDecoder: first byte not zero")
}
for i := 0; i < 4; i++ {
if err = d.updateCode(); err != nil {
return err
}
}
if d.code >= d.nrange {
return errors.New("newRangeDecoder: d.code >= d.nrange")
}
return nil
}
// newRangeDecoder initializes a range decoder. It reads five bytes from the
// reader and therefore may return an error.
func newRangeDecoder(br io.ByteReader) (d *rangeDecoder, err error) {

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -48,7 +48,6 @@ type Reader2 struct {
chunkReader io.Reader
cstate chunkState
ctype chunkType
}
// NewReader2 creates a reader for an LZMA2 chunk sequence.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -53,12 +53,6 @@ func (s *state) Reset() {
s.distCodec.init()
}
// initState initializes the state.
func initState(s *state, p Properties) {
*s = state{Properties: p}
s.Reset()
}
// newState creates a new state from the give Properties.
func newState(p Properties) *state {
s := &state{Properties: p}

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -26,13 +26,6 @@ type ReaderConfig struct {
SingleStream bool
}
// fill replaces all zero values with their default values.
func (c *ReaderConfig) fill() {
if c.DictCap == 0 {
c.DictCap = 8 * 1024 * 1024
}
}
// Verify checks the reader parameters for Validity. Zero values will be
// replaced by default values.
func (c *ReaderConfig) Verify() error {
@ -165,22 +158,16 @@ func (c ReaderConfig) newStreamReader(xz io.Reader) (r *streamReader, err error)
return r, nil
}
// errIndex indicates an error with the xz file index.
var errIndex = errors.New("xz: error in xz file index")
// readTail reads the index body and the xz footer.
func (r *streamReader) readTail() error {
index, n, err := readIndexBody(r.xz)
index, n, err := readIndexBody(r.xz, len(r.index))
if err != nil {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
return err
}
if len(index) != len(r.index) {
return fmt.Errorf("xz: index length is %d; want %d",
len(index), len(r.index))
}
for i, rec := range r.index {
if rec != index[i] {
return fmt.Errorf("xz: record %d is %v; want %v",
@ -265,7 +252,6 @@ type blockReader struct {
n int64
hash hash.Hash
r io.Reader
err error
}
// newBlockReader creates a new block reader.
@ -315,10 +301,6 @@ func (br *blockReader) record() record {
return record{br.unpaddedSize(), br.uncompressedSize()}
}
// errBlockSize indicates that the size of the block in the block header
// is wrong.
var errBlockSize = errors.New("xz: wrong uncompressed size for block")
// Read reads data from the block.
func (br *blockReader) Read(p []byte) (n int, err error) {
n, err = br.r.Read(p)

View file

@ -1,4 +1,4 @@
// Copyright 2014-2019 Ulrich Kunitz. All rights reserved.
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -6,6 +6,7 @@ package xz
import (
"errors"
"fmt"
"hash"
"io"
@ -190,6 +191,9 @@ func (c WriterConfig) NewWriter(xz io.Writer) (w *Writer, err error) {
return nil, err
}
data, err := w.h.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("w.h.MarshalBinary(): error %w", err)
}
if _, err = xz.Write(data); err != nil {
return nil, err
}