Check to avoid division by zero. Fixes #106.

This commit is contained in:
Gunnsteinn Hall 2017-08-06 11:28:39 +00:00
parent 008469dfd2
commit 9ec828c8f7
2 changed files with 10 additions and 0 deletions

View File

@ -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)

View File

@ -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")