Repository navigation
Conversation
…ys how many parts it holds
|
Collaborator
Author
|
Combined into #49, which carries this and the rest of the campaign in one pull request. Nothing is lost: the commits are in it, and the release notes are folded into the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What this is
Three defects a review found, and the limits that were missing from one path.
The write path read a template without any of the limits the read path has. A
template is somebody else's file, and a zip says how its contents are laid out and
nothing about how much room they will take up: forty kilobytes of a part is forty
megabytes of paragraph, and the entry count is whatever the writer felt like.
No
CHECKCONS, no bound on the number of parts, no bound on the size of a part. Theread path has all three, in
Reverse\OptionsandReverse\Package.The message that says a document has too many parts reported zero parts. The
archive was closed before the number was read, and closing an archive resets the
count to zero:
Two findings the analyser raises on
examples/build.php—php:S2003andphp:S1192. Neither changes what the build writes.The issues are #45,
#46 and
#47.
The measure
A
.dotxof sixty-five kilobytes whose[Content_Types].xmlinflates to sixty-fourMiB, and an archive with five thousand parts:
The peak is measured with
memory_get_peak_usage()around a call toTemplatePackage::of(), and the archive on disk is 65783 bytes.What changed
The template is bounded before a part of it is read. The number of parts and the
size of any one of them are checked against the central directory, which costs one
lookup per entry and no decompression:
Every entry is measured, and not only the ones this library reads. The template is
opened again by PHPWord's own processor, and a part that is read there is read whole.
The bounds are the read path's numbers — 4096 parts, 256 MiB each — so a document
is as welcome as a template. A caller who wants them tighter says so:
A template that is over a bound is refused with a
MarkdownWord\Exception\UnreadableTemplate, which is anInvalidInput: the file isthe caller's to fix. A template that cannot be opened at all keeps the
FileNotWritableit has always had, so nothing that catches it stops working.The count in the message is the archive's own, read before the archive is closed.
The tests
Every test fails without the change it covers. Revert the change, run the one test,
watch it fail, put it back.
it('refuses a template that holds more parts than are allowed')it('refuses a template that holds a part larger than is allowed')it('says how many parts a template holds when it refuses it')0it('refuses an archive with more entries in it than the budget allows')0it('refuses a template that is too much through the template itself')it('reads a template that is within the limits')is the other side of the guard — abound that refuses everything refuses the templates that are fine. It passes either
way, and it is not coverage of the change.
The number the messages carry is read out of the archive in the test, so it cannot be
a number that goes stale.
The gates
src,tools,testsandexamples/build.php: no errors.No
ignoreErrors, no baseline, no suppression.composer check: green.A note on the changelog
The entries are under
## [Unreleased], which is the same section#43 adds. Merging this
after it is a one-line resolution — the two sections are the same heading in the same
place.