Skip to content

Commit

Permalink
Fix #758, #770
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Feb 6, 2024
1 parent 9295163 commit 261c563
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pkg/pdfcpu/form/form.go
Expand Up @@ -218,12 +218,34 @@ func isField(xRefTable *model.XRefTable, indRef types.IndirectRef, fields types.
func extractStringSlice(a types.Array) ([]string, error) {
var ss []string
for _, o := range a {
sl, _ := o.(types.StringLiteral)
sl, ok := o.(types.StringLiteral)
if ok {
s, err := types.StringLiteralToString(sl)
if err != nil {
return nil, err
}
s = strings.TrimSpace(s)
if len(s) > 0 {
ss = append(ss, s)
}
continue
}
arr, ok := o.(types.Array)
if !ok || len(arr) != 2 {
return nil, errors.New("corrupt choice field")
}
sl, ok = arr[1].(types.StringLiteral)
if !ok {
return nil, errors.New("corrupt choice field")
}
s, err := types.StringLiteralToString(sl)
if err != nil {
return nil, err
}
ss = append(ss, s)
s = strings.TrimSpace(s)
if len(s) > 0 {
ss = append(ss, s)
}
}
return ss, nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/pdfcpu/read.go
Expand Up @@ -2949,6 +2949,10 @@ func handlePermissions(ctx *model.Context) error {
return errors.New("pdfcpu: corrupted permissions after upw ok")
}

if ctx.OwnerPW == "" && ctx.UserPW == "" {
return nil
}

// Double check minimum permissions for pdfcpu processing.
if !hasNeededPermissions(ctx.Cmd, ctx.E) {
return errors.New("pdfcpu: operation restriced via pdfcpu's permission bits setting")
Expand Down

0 comments on commit 261c563

Please sign in to comment.