From 7e87807d1687aba2b103cef00921066f83aa34ab Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Tue, 18 Jan 2022 23:18:44 +0000 Subject: [PATCH] fuzzy_fastboot: Add malformed download command test Add a malformed download command test. And add a sparse file test with very large block size Bug: 215236564 Test: bootloader fastboot Change-Id: I1072ba189ac15b2e1eb8f13ffd754f93c967e2d5 --- fastboot/fuzzy_fastboot/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fastboot/fuzzy_fastboot/main.cpp b/fastboot/fuzzy_fastboot/main.cpp index 055a0470a..074306b32 100644 --- a/fastboot/fuzzy_fastboot/main.cpp +++ b/fastboot/fuzzy_fastboot/main.cpp @@ -874,6 +874,12 @@ TEST_F(Fuzz, DownloadInvalid8) { << "Device did not respond with FAIL for malformed download command '" << cmd << "'"; } +TEST_F(Fuzz, DownloadInvalid9) { + std::string cmd("download:2PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"); + EXPECT_EQ(fb->RawCommand(cmd), DEVICE_FAIL) + << "Device did not respond with FAIL for malformed download command '" << cmd << "'"; +} + TEST_F(Fuzz, GetVarAllSpam) { auto start = std::chrono::high_resolution_clock::now(); std::chrono::duration elapsed; @@ -996,6 +1002,23 @@ TEST_F(Fuzz, SparseZeroBlkSize) { } } +TEST_F(Fuzz, SparseVeryLargeBlkSize) { + // handcrafted sparse file with block size of ~4GB and divisible 4 + const std::vector buf = { + '\x3a', '\xff', '\x26', '\xed', '\x01', '\x00', '\x00', '\x00', + '\x1c', '\x00', '\x0c', '\x00', '\xF0', '\xFF', '\xFF', '\xFF', + '\x01', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\xc3', '\xca', '\x00', '\x00', + '\x01', '\x00', '\x00', '\x00', '\x0c', '\x00', '\x00', '\x00', + '\x11', '\x22', '\x33', '\x44' + }; + + ASSERT_EQ(DownloadCommand(buf.size()), SUCCESS) << "Device rejected download command"; + ASSERT_EQ(SendBuffer(buf), SUCCESS) << "Downloading payload failed"; + ASSERT_EQ(HandleResponse(), SUCCESS) << "Not receive okay"; + ASSERT_EQ(fb->Flash("userdata"), SUCCESS) << "Flashing sparse failed"; +} + TEST_F(Fuzz, SparseTrimmed) { // handcrafted malform sparse file which is trimmed const std::vector buf = {