Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/common/safe_browsing/mach_o_image_reader_mac_unittest.cc

Issue 1763443002: Protect against recursive processing of the fat header in MachOImageReader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/safe_browsing/mach_o_image_reader_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/safe_browsing/mach_o_image_reader_mac.h" 5 #include "chrome/common/safe_browsing/mach_o_image_reader_mac.h"
6 6
7 #include <arpa/inet.h> 7 #include <arpa/inet.h>
8 #include <libkern/OSByteOrder.h> 8 #include <libkern/OSByteOrder.h>
9 #include <mach-o/fat.h> 9 #include <mach-o/fat.h>
10 #include <mach-o/loader.h> 10 #include <mach-o/loader.h>
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 476
477 const auto& load_commands = reader.GetLoadCommands(); 477 const auto& load_commands = reader.GetLoadCommands();
478 EXPECT_EQ(3u, load_commands.size()); 478 EXPECT_EQ(3u, load_commands.size());
479 479
480 EXPECT_EQ(static_cast<uint32_t>(LC_SEGMENT), load_commands[0].cmd()); 480 EXPECT_EQ(static_cast<uint32_t>(LC_SEGMENT), load_commands[0].cmd());
481 EXPECT_EQ(static_cast<uint32_t>(LC_SYMSEG), load_commands[1].cmd()); 481 EXPECT_EQ(static_cast<uint32_t>(LC_SYMSEG), load_commands[1].cmd());
482 EXPECT_EQ(sizeof(load_command) - 3, load_commands[1].cmdsize()); 482 EXPECT_EQ(sizeof(load_command) - 3, load_commands[1].cmdsize());
483 EXPECT_EQ(static_cast<uint32_t>(LC_SEGMENT), load_commands[2].cmd()); 483 EXPECT_EQ(static_cast<uint32_t>(LC_SEGMENT), load_commands[2].cmd());
484 } 484 }
485 485
486 // https://crbug.com/591194
487 TEST_F(MachOImageReaderTest, RecurseFatHeader) {
488 #pragma pack(push, 1)
489 struct TestImage {
490 fat_header header;
491 fat_arch arch1;
492 fat_arch arch2;
493 mach_header_64 macho64;
494 mach_header macho;
495 };
496 #pragma pack(pop)
497
498 TestImage test_image = {};
499 test_image.header.magic = FAT_MAGIC;
500 test_image.header.nfat_arch = 2;
501 test_image.arch1.offset = offsetof(TestImage, macho64);
502 test_image.arch1.size = sizeof(mach_header_64);
503 test_image.arch2.offset = 0; // Cannot point back at the fat_header.
504 test_image.arch2.size = sizeof(test_image);
505
506 test_image.macho64.magic = MH_MAGIC_64;
507 test_image.macho.magic = MH_MAGIC;
508
509 MachOImageReader reader;
510 EXPECT_FALSE(reader.Initialize(reinterpret_cast<const uint8_t*>(&test_image),
511 sizeof(test_image)));
512 }
513
486 } // namespace 514 } // namespace
487 } // namespace safe_browsing 515 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/common/safe_browsing/mach_o_image_reader_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698