mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Check to avoid division by zero. Fixes #106.
This commit is contained in:
parent
008469dfd2
commit
9ec828c8f7
@ -646,6 +646,11 @@ func (this *LZWEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)
|
||||
common.Log.Trace("Tiff encoding")
|
||||
|
||||
rowLength := int(this.Columns) * this.Colors
|
||||
if rowLength < 1 {
|
||||
// No data. Return empty set.
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
rows := len(outData) / rowLength
|
||||
if len(outData)%rowLength != 0 {
|
||||
common.Log.Debug("ERROR: TIFF encoding: Invalid row length...")
|
||||
@ -679,6 +684,10 @@ func (this *LZWEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)
|
||||
// Columns represents the number of samples per row; Each sample can contain multiple color
|
||||
// components.
|
||||
rowLength := int(this.Columns*this.Colors + 1) // 1 byte to specify predictor algorithms per row.
|
||||
if rowLength < 1 {
|
||||
// No data. Return empty set.
|
||||
return []byte{}, nil
|
||||
}
|
||||
rows := len(outData) / rowLength
|
||||
if len(outData)%rowLength != 0 {
|
||||
return nil, fmt.Errorf("Invalid row length (%d/%d)", len(outData), rowLength)
|
||||
|
@ -70,6 +70,7 @@ func TestLZWEncoding(t *testing.T) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Test run length encoding.
|
||||
func TestRunLengthEncoding(t *testing.T) {
|
||||
rawStream := []byte("this is a dummy text with some \x01\x02\x03 binary data")
|
||||
|
Loading…
x
Reference in New Issue
Block a user