... | ... |
@@ -69,6 +69,7 @@ |
69 | 69 |
|
70 | 70 |
struct pdf_token { |
71 | 71 |
uint32_t flags; /* tracking flags */ |
72 |
+ uint32_t success; /* successfully decoded filters */ |
|
72 | 73 |
|
73 | 74 |
uint32_t length; /* length of current content */ |
74 | 75 |
uint8_t *content; /* content stream */ |
... | ... |
@@ -112,6 +113,8 @@ off_t pdf_decodestream(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_d |
112 | 112 |
if (xref) |
113 | 113 |
token->flags |= PDFTOKEN_FLAG_XREF; |
114 | 114 |
|
115 |
+ token->success = 0; |
|
116 |
+ |
|
115 | 117 |
token->content = cli_malloc(streamlen); |
116 | 118 |
if (!token->content) { |
117 | 119 |
free(token); |
... | ... |
@@ -133,14 +136,28 @@ off_t pdf_decodestream(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_d |
133 | 133 |
*rc = CL_SUCCESS; |
134 | 134 |
} |
135 | 135 |
|
136 |
- if (!cli_checklimits("pdf", pdf->ctx, token->length, 0, 0)) { |
|
137 |
- if (cli_writen(fout, token->content, token->length) != token->length) { |
|
138 |
- cli_errmsg("cli_pdf: failed to write output file\n"); |
|
139 |
- if (rc) |
|
140 |
- *rc = CL_EWRITE; |
|
141 |
- return -1; |
|
136 |
+ if (token->success) { |
|
137 |
+ if (!cli_checklimits("pdf", pdf->ctx, token->length, 0, 0)) { |
|
138 |
+ if (cli_writen(fout, token->content, token->length) != token->length) { |
|
139 |
+ cli_errmsg("cli_pdf: failed to write output file\n"); |
|
140 |
+ if (rc) |
|
141 |
+ *rc = CL_EWRITE; |
|
142 |
+ return -1; |
|
143 |
+ } |
|
144 |
+ rv = token->length; |
|
145 |
+ } |
|
146 |
+ } else { /* if no non-forced filter are decoded, return the raw stream */ |
|
147 |
+ if (!cli_checklimits("pdf", pdf->ctx, streamlen, 0, 0)) { |
|
148 |
+ cli_dbgmsg("cli_pdf: no non-forced filters decoded, returning raw stream\n"); |
|
149 |
+ |
|
150 |
+ if (cli_writen(fout, stream, streamlen) != streamlen) { |
|
151 |
+ cli_errmsg("cli_pdf: failed to write output file\n"); |
|
152 |
+ if (rc) |
|
153 |
+ *rc = CL_EWRITE; |
|
154 |
+ return -1; |
|
155 |
+ } |
|
156 |
+ rv = streamlen; |
|
142 | 157 |
} |
143 |
- rv = token->length; |
|
144 | 158 |
} |
145 | 159 |
|
146 | 160 |
free(token->content); |
... | ... |
@@ -248,6 +265,7 @@ static int pdf_decodestream_internal(struct pdf_struct *pdf, struct pdf_obj *obj |
248 | 248 |
break; |
249 | 249 |
} |
250 | 250 |
} |
251 |
+ token->success++; |
|
251 | 252 |
|
252 | 253 |
if (cl_engine_get_num(pdf->ctx->engine, CL_ENGINE_FORCETODISK, NULL) && |
253 | 254 |
cl_engine_get_num(pdf->ctx->engine, CL_ENGINE_KEEPTMP, NULL)) { |