2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Fix infinite loop on small files with progress reporting (fixes #230)

Turns out you can keep adding zero to a number over and over again and
it just doesn't get any bigger. Who would have known?
This commit is contained in:
Jay Berkenbilt 2018-08-05 15:42:01 -04:00
parent 651b51f056
commit e1cd5891af
4 changed files with 21 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2018-08-05 Jay Berkenbilt <ejb@ql.org>
* Bug fix: infinite loop on progress reporting for very small
files. Fixes #230.
2018-08-04 Jay Berkenbilt <ejb@ql.org>
* Performance fix: optimize page merging operation to avoid

View File

@ -3357,9 +3357,10 @@ QPDFWriter::indicateProgress(bool decrement, bool finished)
this->m->events_expected)));
this->m->progress_reporter->reportProgress(percentage);
}
int increment = std::max(1, (this->m->events_expected / 100));
while (this->m->events_seen >= this->m->next_progress_report)
{
this->m->next_progress_report += (this->m->events_expected / 100);
this->m->next_progress_report += increment;
}
}

View File

@ -925,6 +925,17 @@ $td->runtest("don't overwrite self",
{$td->REGEXP => "input file and output file are the same.*",
$td->EXIT_STATUS => 2});
show_ntests();
# ----------
$td->notify("--- Progress reporting ---");
$n_tests += 1;
$td->runtest("progress report on small file",
{$td->COMMAND => "qpdf --progress minimal.pdf a.pdf",
$td->FILTER => "perl filter-progress.pl"},
{$td->FILE => "small-progress.out", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
show_ntests();
# ----------
$td->notify("--- Type checks ---");

View File

@ -0,0 +1,3 @@
qpdf: a.pdf: write progress: 0%
....other write progress....
qpdf: a.pdf: write progress: 100%