Skip to content

Commit 3744f3c

Browse files
committed
Fix #1185
1 parent b419ce4 commit 3744f3c

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

pkg/pdfcpu/model/parse.go

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,10 @@ func startParseNumericOrIndRef(l string) (string, string, int) {
664664
0.000000000
665665
*/
666666
if len(str) > 1 && str[0] == '0' {
667-
if str[1] == '+' || str[1] == '-' {
667+
switch str[1] {
668+
case '+', '-':
668669
str = str[1:]
669-
} else if str[1] == '.' {
670+
case '.':
670671
var i int
671672
for i = 2; len(str) > i && str[i] == '0'; i++ {
672673
}
@@ -687,8 +688,7 @@ func isRangeError(err error) bool {
687688
return false
688689
}
689690

690-
func parseIndRef(s, l, l1 string, line *string, i, i2 int, rangeErr bool) (types.Object, error) {
691-
691+
func parseIndRef(s, l, l1 string, line *string, i, i2 int) (types.Object, error) {
692692
g, err := strconv.Atoi(s)
693693
if err != nil {
694694
// 2nd int(generation number) not available.
@@ -704,27 +704,17 @@ func parseIndRef(s, l, l1 string, line *string, i, i2 int, rangeErr bool) (types
704704
l, _ = trimLeftSpace(l, false)
705705

706706
if len(l) == 0 {
707-
if rangeErr {
708-
return nil, err
709-
}
710707
// only whitespace
711708
*line = l1
712709
return types.Integer(i), nil
713710
}
714711

715712
if l[0] == 'R' {
716713
*line = forwardParseBuf(l, 1)
717-
if rangeErr {
718-
return nil, nil
719-
}
720714
// We have all 3 components to create an indirect reference.
721715
return *types.NewIndirectRef(i, g), nil
722716
}
723717

724-
if rangeErr {
725-
return nil, err
726-
}
727-
728718
// 'R' not available.
729719
// Can't be an indirect reference.
730720
if log.ParseEnabled() {
@@ -765,29 +755,22 @@ func parseNumericOrIndRef(line *string) (types.Object, error) {
765755
s, l1, i1 := startParseNumericOrIndRef(l)
766756

767757
// Try int
768-
var rangeErr bool
769758
i, err := strconv.Atoi(s)
770759
if err != nil {
771-
rangeErr = isRangeError(err)
772-
if !rangeErr {
773-
// Try float
760+
if isRangeError(err) {
761+
// #407
762+
i = 0
774763
*line = l1
775-
return parseFloat(s)
764+
return types.Integer(i), nil
776765
}
777-
778-
// #407
779-
i = 0
766+
*line = l1
767+
return parseFloat(s)
780768
}
781769

782770
// We have an Int!
783771

784772
// if not followed by whitespace return sole integer value.
785773
if i1 <= 0 || delimiter(l[i1]) {
786-
787-
if rangeErr {
788-
return nil, err
789-
}
790-
791774
if log.ParseEnabled() {
792775
log.Parse.Printf("parseNumericOrIndRef: value is numeric int: %d\n", i)
793776
}
@@ -802,9 +785,6 @@ func parseNumericOrIndRef(line *string) (types.Object, error) {
802785
l, _ = trimLeftSpace(l, false)
803786
if len(l) == 0 {
804787
// only whitespace
805-
if rangeErr {
806-
return nil, err
807-
}
808788
*line = l1
809789
return types.Integer(i), nil
810790
}
@@ -814,9 +794,6 @@ func parseNumericOrIndRef(line *string) (types.Object, error) {
814794
// if only 2 token, can't be indirect reference.
815795
// if not followed by whitespace return sole integer value.
816796
if i2 <= 0 || delimiter(l[i2]) {
817-
if rangeErr {
818-
return nil, err
819-
}
820797
if log.ParseEnabled() {
821798
log.Parse.Printf("parseNumericOrIndRef: 2 objects => value is numeric int: %d\n", i)
822799
}
@@ -829,7 +806,7 @@ func parseNumericOrIndRef(line *string) (types.Object, error) {
829806
s = l[:i2]
830807
}
831808

832-
return parseIndRef(s, l, l1, line, i, i2, rangeErr)
809+
return parseIndRef(s, l, l1, line, i, i2)
833810
}
834811

835812
func parseHexLiteralOrDict(c context.Context, l *string) (val types.Object, err error) {

pkg/testdata/ExtGStateImage.pdf

-28.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)