summaryrefslogtreecommitdiff
path: root/libgo/go/compress/bzip2/bzip2.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/compress/bzip2/bzip2.go')
-rw-r--r--libgo/go/compress/bzip2/bzip2.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/libgo/go/compress/bzip2/bzip2.go b/libgo/go/compress/bzip2/bzip2.go
index 68979572708..42788443bcf 100644
--- a/libgo/go/compress/bzip2/bzip2.go
+++ b/libgo/go/compress/bzip2/bzip2.go
@@ -27,9 +27,8 @@ type reader struct {
blockCRC uint32
wantBlockCRC uint32
setupDone bool // true if we have parsed the bzip2 header.
- blockSize int // blockSize in bytes, i.e. 900 * 1024.
+ blockSize int // blockSize in bytes, i.e. 900 * 1000.
eof bool
- buf []byte // stores Burrows-Wheeler transformed data.
c [256]uint // the `C' array for the inverse BWT.
tt []uint32 // mirrors the `tt' array in the bzip2 source and contains the P array in the upper 24 bits.
tPos uint32 // Index of the next output byte in tt.
@@ -76,7 +75,7 @@ func (bz2 *reader) setup(needMagic bool) error {
}
bz2.fileCRC = 0
- bz2.blockSize = 100 * 1024 * (int(level) - '0')
+ bz2.blockSize = 100 * 1000 * (level - '0')
if bz2.blockSize > len(bz2.tt) {
bz2.tt = make([]uint32, bz2.blockSize)
}
@@ -294,7 +293,7 @@ func (bz2 *reader) readBlock() (err error) {
if c >= numHuffmanTrees {
return StructuralError("tree index too large")
}
- treeIndexes[i] = uint8(mtfTreeDecoder.Decode(c))
+ treeIndexes[i] = mtfTreeDecoder.Decode(c)
}
// The list of symbols for the move-to-front transform is taken from
@@ -319,6 +318,9 @@ func (bz2 *reader) readBlock() (err error) {
length := br.ReadBits(5)
for j := range lengths {
for {
+ if length < 1 || length > 20 {
+ return StructuralError("Huffman length out of range")
+ }
if !br.ReadBit() {
break
}
@@ -328,9 +330,6 @@ func (bz2 *reader) readBlock() (err error) {
length++
}
}
- if length < 0 || length > 20 {
- return StructuralError("Huffman length out of range")
- }
lengths[j] = uint8(length)
}
huffmanTrees[i], err = newHuffmanTree(lengths)
@@ -400,7 +399,7 @@ func (bz2 *reader) readBlock() (err error) {
return StructuralError("repeats past end of block")
}
for i := 0; i < repeat; i++ {
- b := byte(mtf.First())
+ b := mtf.First()
bz2.tt[bufIndex] = uint32(b)
bz2.c[b]++
bufIndex++
@@ -421,7 +420,7 @@ func (bz2 *reader) readBlock() (err error) {
// it's always referenced with a run-length of 1. Thus 0
// doesn't need to be encoded and we have |v-1| in the next
// line.
- b := byte(mtf.Decode(int(v - 1)))
+ b := mtf.Decode(int(v - 1))
if bufIndex >= bz2.blockSize {
return StructuralError("data exceeds block size")
}