mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-24 13:48:49 +08:00
Prevent crashing when processing content stream (#291)
* Skip invalid pop operation on empty graphics state stacks * Fix clipping input values to size for Type 0 Functions * Do not pass invalid Q content stream operator to external handlers
This commit is contained in:
parent
c582323a8f
commit
64a43b38d2
@ -230,6 +230,10 @@ func (proc *ContentStreamProcessor) Process(resources *model.PdfPageResources) e
|
||||
case "q":
|
||||
proc.graphicsStack.Push(proc.graphicsState)
|
||||
case "Q":
|
||||
if len(proc.graphicsStack) == 0 {
|
||||
common.Log.Debug("WARN: invalid `Q` operator. Graphics state stack is empty. Skipping.")
|
||||
continue
|
||||
}
|
||||
proc.graphicsState = proc.graphicsStack.Pop()
|
||||
|
||||
// Color operations (Table 74 p. 179)
|
||||
|
@ -306,10 +306,10 @@ func (f *PdfFunctionType0) Evaluate(x []float64) ([]float64, error) {
|
||||
for i := 0; i < len(x); i++ {
|
||||
xi := x[i]
|
||||
|
||||
// See section 7.10.2 Type 0 (Sampled) Functions (pp. 93-94 PDF32000_2008).
|
||||
xip := math.Min(math.Max(xi, f.Domain[2*i]), f.Domain[2*i+1])
|
||||
|
||||
ei := interpolate(xip, f.Domain[2*i], f.Domain[2*i+1], encode[2*i], encode[2*i+1])
|
||||
eip := math.Min(math.Max(ei, 0), float64(f.Size[i]))
|
||||
eip := math.Min(math.Max(ei, 0), float64(f.Size[i]-1))
|
||||
// eip represents coordinate into the data table.
|
||||
// At this point it is real values.
|
||||
|
||||
@ -325,7 +325,6 @@ func (f *PdfFunctionType0) Evaluate(x []float64) ([]float64, error) {
|
||||
index = f.Size[i] - 1
|
||||
}
|
||||
indices = append(indices, index)
|
||||
|
||||
}
|
||||
|
||||
// Calculate the index
|
||||
|
Loading…
x
Reference in New Issue
Block a user