Skip to content

Commit 9310068

Browse files
committed
Fix #1072
1 parent eb132fb commit 9310068

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

pkg/pdfcpu/read.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1349,13 +1349,14 @@ func parseAndLoad(c context.Context, ctx *model.Context, line string, offset *in
13491349
return nil
13501350
}
13511351

1352-
d, ok := o.(types.Dict)
1353-
if ok && ctx.RootDict == nil {
1354-
if typ := d.Type(); typ != nil {
1355-
if *typ == "Catalog" {
1356-
ctx.RootDict = d
1357-
ctx.Root = types.NewIndirectRef(*objNr, *generation)
1358-
model.ShowRepaired("catalog")
1352+
if ctx.RootDict == nil {
1353+
if d, ok := o.(types.Dict); ok {
1354+
if typ := d.Type(); typ != nil {
1355+
if *typ == "Catalog" {
1356+
ctx.RootDict = d
1357+
ctx.Root = types.NewIndirectRef(*objNr, *generation)
1358+
model.ShowRepaired("catalog")
1359+
}
13591360
}
13601361
}
13611362
}

pkg/pdfcpu/validate/page.go

+10
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ func validatePageContents(xRefTable *model.XRefTable, d types.Dict) (hasContents
128128
d.Delete("Contents")
129129
model.ShowRepaired("page dict \"Contents\"")
130130

131+
case types.Dict:
132+
133+
if len(o) > 0 || xRefTable.ValidationMode == model.ValidationStrict {
134+
return false, errors.Errorf("validatePageContents: page content must be stream dict or array, got: %T", o)
135+
}
136+
137+
// Digest empty dict.
138+
d.Delete("Contents")
139+
model.ShowRepaired("page dict \"Contents\"")
140+
131141
default:
132142
return false, errors.Errorf("validatePageContents: page content must be stream dict or array, got: %T", o)
133143
}

0 commit comments

Comments
 (0)