mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-09 19:29:34 +08:00
Merge remote-tracking branch 'upstream/master' into xmaster2
This commit is contained in:
commit
a96a007238
@ -270,10 +270,13 @@ func (this *FlateEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, erro
|
||||
common.Log.Debug("ERROR: TIFF encoding: Invalid row length...")
|
||||
return nil, fmt.Errorf("Invalid row length (%d/%d)", len(outData), rowLength)
|
||||
}
|
||||
|
||||
if rowLength%this.Colors != 0 {
|
||||
return nil, fmt.Errorf("Invalid row length (%d) for colors %d", rowLength, this.Colors)
|
||||
}
|
||||
if rowLength > len(outData) {
|
||||
common.Log.Debug("Row length cannot be longer than data length (%d/%d)", rowLength, len(outData))
|
||||
return nil, errors.New("Range check error")
|
||||
}
|
||||
common.Log.Trace("inp outData (%d): % x", len(outData), outData)
|
||||
|
||||
pOutBuffer := bytes.NewBuffer(nil)
|
||||
@ -300,6 +303,10 @@ func (this *FlateEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, erro
|
||||
if len(outData)%rowLength != 0 {
|
||||
return nil, fmt.Errorf("Invalid row length (%d/%d)", len(outData), rowLength)
|
||||
}
|
||||
if rowLength > len(outData) {
|
||||
common.Log.Debug("Row length cannot be longer than data length (%d/%d)", rowLength, len(outData))
|
||||
return nil, errors.New("Range check error")
|
||||
}
|
||||
|
||||
pOutBuffer := bytes.NewBuffer(nil)
|
||||
|
||||
@ -652,6 +659,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...")
|
||||
@ -661,6 +673,11 @@ func (this *LZWEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)
|
||||
if rowLength%this.Colors != 0 {
|
||||
return nil, fmt.Errorf("Invalid row length (%d) for colors %d", rowLength, this.Colors)
|
||||
}
|
||||
|
||||
if rowLength > len(outData) {
|
||||
common.Log.Debug("Row length cannot be longer than data length (%d/%d)", rowLength, len(outData))
|
||||
return nil, errors.New("Range check error")
|
||||
}
|
||||
common.Log.Trace("inp outData (%d): % x", len(outData), outData)
|
||||
|
||||
pOutBuffer := bytes.NewBuffer(nil)
|
||||
@ -685,12 +702,16 @@ 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)
|
||||
}
|
||||
if rowLength > len(outData) {
|
||||
common.Log.Trace("Row length cannot be longer than data length (%d/%d)", rowLength, len(outData))
|
||||
common.Log.Debug("Row length cannot be longer than data length (%d/%d)", rowLength, len(outData))
|
||||
return nil, errors.New("Range check error")
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
@ -9,6 +9,8 @@ package ps
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/unidoc/unidoc/common"
|
||||
)
|
||||
|
||||
// A PSExecutor has its own execution stack and is used to executre a PS routine (program).
|
||||
@ -52,6 +54,7 @@ func (this *PSExecutor) Execute(objects []PSObject) ([]PSObject, error) {
|
||||
|
||||
err := this.program.Exec(this.Stack)
|
||||
if err != nil {
|
||||
common.Log.Debug("Exec failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -587,6 +587,12 @@ func (this *PSOperand) Dup(stack *PSStack) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Push it back.
|
||||
err = stack.Push(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Push the duplicate.
|
||||
err = stack.Push(obj.Duplicate())
|
||||
return err
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.SetLogger(common.ConsoleLogger{})
|
||||
common.SetLogger(common.NewConsoleLogger(common.LogLevelDebug))
|
||||
//common.SetLogger(common.NewConsoleLogger(common.LogLevelTrace))
|
||||
}
|
||||
|
||||
func makeReaderForText(txt string) *bufio.Reader {
|
||||
@ -270,6 +271,8 @@ func TestFunctionOperations(t *testing.T) {
|
||||
|
||||
func TestVariousCases(t *testing.T) {
|
||||
testcases := []ComplexTestEntry{
|
||||
// dup
|
||||
{progText: "{ 99 dup }", expected: "[ int:99 int:99 ]"},
|
||||
// ceiling
|
||||
{progText: "{ 3.2 ceiling }", expected: "[ real:4.00000 ]"},
|
||||
{progText: "{ -4.8 ceiling }", expected: "[ real:-4.00000 ]"},
|
||||
@ -405,3 +408,24 @@ func TestVariousCases(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTintTransform1(t *testing.T) {
|
||||
testcases := []ComplexTestEntry{
|
||||
// from corpus epson_pages3_color_pages1.pdf.
|
||||
{progText: "{ 0.0000 dup 0 mul exch dup 0 mul exch dup 0 mul exch 1 mul }", expected: "[ real:0.00000 real:0.00000 real:0.00000 real:0.00000 ]"},
|
||||
}
|
||||
|
||||
for _, testcase := range testcases {
|
||||
stack, err := quickTest(testcase.progText)
|
||||
if err != nil {
|
||||
t.Errorf("Error: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Maybe not the most robust test (comparing the strings), but should do.
|
||||
if stack.DebugString() != testcase.expected {
|
||||
t.Errorf("Wrong result: '%s' != '%s'", stack.DebugString(), testcase.expected)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user