aboutsummaryrefslogtreecommitdiff
path: root/zucchini_apply.cc
AgeCommit message (Collapse)Author
2021-07-25components: Replace base::Optional and friends with absl counterpartsAnton Bikineev
This replaces: - base::Optional -> absl::optional - include "base/optional.h" -> include "third_party/abseil-cpp/absl/types/optional.h" - base::nullopt -> absl::nullopt - base::make_optional -> absl::make_optional Bug: 1202909 Change-Id: If697b7bf69b199c1796f873eedca3359cdb48c64 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2897151 Commit-Queue: Anton Bikineev <bikineev@chromium.org> Owners-Override: Anton Bikineev <bikineev@chromium.org> Reviewed-by: Peter Kasting <pkasting@chromium.org> Cr-Commit-Position: refs/heads/master@{#883296} NOKEYCHECK=True GitOrigin-RevId: 1156b5f891de178171e71b9221a96bef1ced3d3b
2021-07-25[Zucchini]: Fix OffsetMapper implicit conversion.Etienne Pierre-doray
Fix compile error with -Wshorten-64-to-32. Image size is new stored as an offset_t to avoid implicit conversion. Bug: 881008 Change-Id: I82b12ce17d8368f05d6a5537fd1734ee32b37dbe Reviewed-on: https://chromium-review.googlesource.com/1213549 Reviewed-by: Samuel Huang <huangs@chromium.org> Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org> Cr-Commit-Position: refs/heads/master@{#589938} NOKEYCHECK=True GitOrigin-RevId: 5946dbfa3f684d8f4960bb413b5e8322ebddcee3
2021-07-25[Zucchini] Fix underflow / overflow for extended forward-projection.Samuel Huang
Forward-projection is how Zucchini uses the equivalence map to create estimated "new" targets from "old" targets. Extended forward-projection is defined to transform non-covered offsets: Given an offset, it finds the equivalence unit with nearest "old" block, then applies the "old"-to-"new" displacement to the offset. However, this makes it possible to map an "old" offset to an offset outside "new" image. Another issue is that Zucchini uses "dangling targets" that use "fake offsets" outside the image file to represent .bss data. These targets also undergo forward-projection, and should be properly handled. This CL fixes the existing behavior, where underflow / overflow go unchecked (although these values are rendered benign downstream, since the nearest actual "new" target is found). The updated extended forward-projection specifies: - For "old" targets with real offsets: Take nearest equivalence unit, clamp output to be inside [0, "new" image size). - For "old" dangling targets with fake offsets: Use difference in file size as displacement. The main impact w.r.t. patch is to reduce possible variance in patch sizes -- dangling targets are now handled better. Extensive unit tests are also added. Bug: 832572 Change-Id: I41fea175e4c13585d14a97a712a191afc2fcc6d6 Reviewed-on: https://chromium-review.googlesource.com/1111467 Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#570401} NOKEYCHECK=True GitOrigin-RevId: ad7a5c086f00de62997714b84d6d6b5817ccc9d8
2021-07-25[Zucchini] Refactor Zucchini-gen in zucchini_io layer.Samuel Huang
This CL moves Zucchini-gen invocation code from zucchini_commands.cc (in target zucchini) to zucchini_integration.cc (in target zucchini_io) to clean up layering in Zucchini API, i.e.: - zucchini_lib: Operates on buffers only. - zucchini_io: Adds files interface, uses memory-mapped I/O. - zucchini: Stand-alone executable that parses command-line arguments. Other changes: - Rename zucchini_lib functions (zuchcini.h), to dedup names and emphasize that these functions operate on buffers: - GenerateEnsemble() -> GenerateBuffer(), - GenerateEnsembleWithImposedMatches() -> GenerateBufferImposed(), - GenerateRaw() -> GenerateBufferRaw(), - Apply() -> ApplyBuffer(). These renames only affect Zucchini and various tests. - Variable renames and parameter reordering in zucchini_integration.cc. - Remove '-dd' param in help text of Zucchini-detect (was never ported from Trunk, and has been recently deleted there as well). - Replace all base::File&& with base::File. - Miscellaneous cleanup for header include. - Update README.md. Change-Id: I835b80d4d3d7b291fa822a7a89dab225bf9171e9 Reviewed-on: https://chromium-review.googlesource.com/1105625 Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#569274} NOKEYCHECK=True GitOrigin-RevId: 9f0f325d6e2595deb8d50c77e0464946f3bf1ec1
2021-07-23[Zucchini]: Fix CHECK failure in ApplyCalder Kitagawa
Fixes a CHECK failure in Zucchini Apply found by ClusterFuzz. Scenario: A disassembler parses an image element and shrinks it to be the understood size. Apply expects that this understood size is identical to the size of the element it is trying to patch. This expectation will always hold for "good" patch data but for an arbitary patch may not. This results in a CHECK failure when getting reference writers. Solution: After parsing, check that the disassembler sizes match their respective image sizes. Fail to Apply and print an error message if this is not the case. Bug: 847278 Change-Id: I96edb738b8f9ea2d16193ea1aa2def7319ee8f70 Reviewed-on: https://chromium-review.googlesource.com/1076369 Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org> Reviewed-by: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#562560} NOKEYCHECK=True GitOrigin-RevId: 0ca1928abfdce0efe539655cc09e9a8f4ece063f
2021-07-23[Zucchini]: Fix bugs found by Apply fuzzerCalder Kitagawa
Located by fuzzing ZTF Apply (WIP): https://chromium-review.googlesource.com/c/chromium/src/+/1072231 Found two fatal errors: - OffsetForKey always assumes a key is valid however, the validity of the key is not checked prior to the caller invoking the method. The caller also had no way to check validity if it was external to TargetPool. Fix: Add a method to check for key validity ahead of calling OffsetForKey. - ConvertToTargetLineCol for absolute references had a logic bug that resulted in attempting to dereference an invalid base::Optional Fix: Change the logic to avoid issue. Bug: 835341 Change-Id: I99c91741eef41dfaa3036af8e708eb3f0d5ca84a Reviewed-on: https://chromium-review.googlesource.com/1072272 Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org> Reviewed-by: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#561642} NOKEYCHECK=True GitOrigin-RevId: 4e3e49f97119d48ba6c048e46aa9671d1cd21d17
2021-07-23[Zucchini] Validate equivalences on loadCalder Kitagawa
A follow-up to https://chromium-review.googlesource.com/c/chromium/src/+/1028575 This moves patch_apply logic to check bounds of an equivalences from the call site of GetNext() to an internal function in the patch_reader. This means the equivalence consumer can use the equivalences without checking anything to do with bounds. I have manually tested that this doesn't appear to break any existing valid patches and it appears to catch all the same errors change 1028575 fixed so I can safely reverse that change. BUG: 837096 Change-Id: I84ccd9e1493f32d16eace4dd8e67586f559220d3 Reviewed-on: https://chromium-review.googlesource.com/1028836 Commit-Queue: Calder Kitagawa <ckitagawa@google.com> Reviewed-by: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#554536} NOKEYCHECK=True GitOrigin-RevId: ce5642400b37f5ff2b0a1213522f984bca8a080a
2021-07-23[Zucchini] Fix bugs found by fuzzer in ApplyCalder Kitagawa
There was an outstanding TODO to validate that during Apply the writes to the |new_image| and copies from the |old_image| were within valid ranges. During raw apply fuzzing a number of memory violations occurred this is a fix for those. Bug: 835341 Change-Id: I669304e93e51ba7cd2b862189fbc0a6f3cea1748 Reviewed-on: https://chromium-review.googlesource.com/1028575 Commit-Queue: Calder Kitagawa <ckitagawa@google.com> Reviewed-by: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#553718} NOKEYCHECK=True GitOrigin-RevId: 520aebd16201c0179ff347c7244d940d64af775e
2021-07-23[Zucchini] Move Zucchini from /chrome/installer/ to /components/.Samuel Huang
(Use "git log --follow" to see older revisions of files). /components/ is the most logical place to put Zucchini, which only depends on /base and /testing/gtest. This move also enables Zucchini to be used by the Component Updater. Details: - Move all files; run the following to change deps and guards: sed 's/chrome\/installer/components/' *.cc *.h -i sed 's/CHROME_INSTALLER/COMPONENTS/' *.cc *.h -i - Sorting works out pretty well! - Change all 'chrome/installer/zucchini' to 'components/zucchini' throughout other parts of the repo; sort if necessary. - Fix 6 'git cl lint' errors. - Change 1 Bind() usage to BindRepeated(). - Update OWNER. Bug: 729154 Change-Id: I50c5a7d411ea85f707b5994ab319dfb2a1acccf7 Reviewed-on: https://chromium-review.googlesource.com/954923 Reviewed-by: Greg Thompson <grt@chromium.org> Reviewed-by: Jochen Eisinger <jochen@chromium.org> Reviewed-by: Samuel Huang <huangs@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#542857} NOKEYCHECK=True GitOrigin-RevId: 577ef6c435e8d43be6e3e60ccbcbd1881780f4ec