Commit 56c43934e569ee3e5853206e9b8ee33427aa8c48
1 parent
772cd8d5
Refactor stream filter handling for improved validation.
Simplify and reorganize parsing logic to replace explicit filter name collection with direct filter creation. Added validation for unsupported filters, ensuring filters are cleared and errors returned when necessary. This improves code clarity and robustness.
Showing
1 changed file
with
12 additions
and
13 deletions
libqpdf/QPDF_Stream.cc
| @@ -352,15 +352,17 @@ Stream::filterable( | @@ -352,15 +352,17 @@ Stream::filterable( | ||
| 352 | 352 | ||
| 353 | auto filter_obj = s->stream_dict.getKey("/Filter"); | 353 | auto filter_obj = s->stream_dict.getKey("/Filter"); |
| 354 | 354 | ||
| 355 | - std::vector<std::string> filter_names; | ||
| 356 | - | ||
| 357 | if (filter_obj.isNull()) { | 355 | if (filter_obj.isNull()) { |
| 358 | // No filters | 356 | // No filters |
| 359 | return true; | 357 | return true; |
| 360 | } | 358 | } |
| 361 | if (filter_obj.isName()) { | 359 | if (filter_obj.isName()) { |
| 362 | // One filter | 360 | // One filter |
| 363 | - filter_names.emplace_back(filter_obj.getName()); | 361 | + auto ff = s->filter_factory(filter_obj.getName()); |
| 362 | + if (!ff) { | ||
| 363 | + return false; | ||
| 364 | + } | ||
| 365 | + filters.emplace_back(ff()); | ||
| 364 | } else if (filter_obj.isArray()) { | 366 | } else if (filter_obj.isArray()) { |
| 365 | // Potentially multiple filters | 367 | // Potentially multiple filters |
| 366 | int n = filter_obj.getArrayNItems(); | 368 | int n = filter_obj.getArrayNItems(); |
| @@ -370,21 +372,18 @@ Stream::filterable( | @@ -370,21 +372,18 @@ Stream::filterable( | ||
| 370 | warn("stream filter type is not name or array"); | 372 | warn("stream filter type is not name or array"); |
| 371 | return false; | 373 | return false; |
| 372 | } | 374 | } |
| 373 | - filter_names.emplace_back(item.getName()); | 375 | + auto ff = s->filter_factory(item.getName()); |
| 376 | + if (!ff) { | ||
| 377 | + filters.clear(); | ||
| 378 | + return false; | ||
| 379 | + } | ||
| 380 | + filters.emplace_back(ff()); | ||
| 374 | } | 381 | } |
| 375 | } else { | 382 | } else { |
| 376 | warn("stream filter type is not name or array"); | 383 | warn("stream filter type is not name or array"); |
| 377 | return false; | 384 | return false; |
| 378 | } | 385 | } |
| 379 | 386 | ||
| 380 | - for (auto& filter_name: filter_names) { | ||
| 381 | - if (auto ff = s->filter_factory(filter_name)) { | ||
| 382 | - filters.emplace_back(ff()); | ||
| 383 | - continue; | ||
| 384 | - } | ||
| 385 | - return false; | ||
| 386 | - } | ||
| 387 | - | ||
| 388 | bool filterable = true; | 387 | bool filterable = true; |
| 389 | 388 | ||
| 390 | // filters now contains a list of filters to be applied in order. See which ones we can support. | 389 | // filters now contains a list of filters to be applied in order. See which ones we can support. |
| @@ -401,7 +400,7 @@ Stream::filterable( | @@ -401,7 +400,7 @@ Stream::filterable( | ||
| 401 | decode_parms.push_back(decode_obj.getArrayItem(i)); | 400 | decode_parms.push_back(decode_obj.getArrayItem(i)); |
| 402 | } | 401 | } |
| 403 | } else { | 402 | } else { |
| 404 | - for (unsigned int i = 0; i < filter_names.size(); ++i) { | 403 | + for (unsigned int i = 0; i < filters.size(); ++i) { |
| 405 | decode_parms.push_back(decode_obj); | 404 | decode_parms.push_back(decode_obj); |
| 406 | } | 405 | } |
| 407 | } | 406 | } |