嗓子不舒服吃什么消炎药| 分山念什么| 副乳挂什么科| 考号是什么| 坤沙酒是什么意思| 0属于什么数| 身体虚弱打什么营养针| 洛神花是什么花| 十斋日是什么意思| 锅底灰能治什么病| 一暴十寒什么意思| 熊猫尾巴什么颜色| 胃火重吃什么药| 三月份是什么星座| 猕猴桃什么季节成熟| 港澳通行证办理需要什么证件| 腰痛看什么科| 为什么得疱疹病毒| 灭活是什么意思| 刚是什么意思| 野格是什么酒| 属猴配什么属相最好| 什么是白条| 焦虑症看什么科室| 肝素是什么| 什么是双飞| 小酌怡情下一句是什么| 长江学者是什么级别| hr过高是什么意思| 熬夜喝什么好| 麝是什么动物| 痔疮的症状是什么| 肝胆湿热吃什么中成药| 6月20日是什么节日| 脖子后面有痣代表什么| 带银饰有什么好处| 为什么会突然晕倒| 芋圆是什么| 切除子宫对身体有什么伤害| 珩五行属什么| 尿胆原阳性是什么意思| 甲状腺功能是什么| 女性痔疮挂什么科室| 年岁是什么意思| 秀才相当于现在的什么学历| 精湛是什么意思| 什么人容易中暑| 关东煮是什么| 做肠镜前一天可以吃什么| 麻烦的意思是什么| 脾胃不好能吃什么水果| 鳞状细胞是什么意思| 耳朵真菌感染用什么药| 百香果什么味道| 梅雨季节是什么时间| 鬼剃头是什么原因| 如常是什么意思| 什么树叶| yishion是什么牌子| 初级中学是什么意思| 什么人不能吃鹅蛋| 纨绔子弟什么意思| 女性排卵期有什么表现| 手突然抖动是什么原因| 今天是什么日子| 舌头边疼是什么原因| 1994是什么年| 五味杂粮什么意思| npv是什么意思| strange什么意思| 肩周炎不能吃什么食物| 一什么水花| 见人说人话见鬼说鬼话是什么意思| 老有痰是什么原因| 浪凡算是什么档次的| 黑胡椒和白胡椒有什么区别| 吃什么解暑| 扑救带电火灾应选用什么灭火器| 什么的水花| 吃饺子是什么节日| 眼镜pd是什么意思| 胰岛素为什么不能口服| 血糖仪什么牌子的好用又准确| 过堂是什么意思| 卟啉病是什么病| 口干舌燥是什么原因| 学名是什么意思| 左派是什么意思| 手指关节肿胀是什么原因| 什么叫试管婴儿| 两个人可以玩什么游戏| 大便里急后重什么意思| size是什么意思| 乌云为什么是黑色的| 米饭配什么菜好吃| 荨麻疹要注意些什么| 逝者如斯夫什么意思| 喝什么解渴| 二月初九是什么星座| 什么叫化学| 乳痈是什么意思| 嗓子有异物感吃什么药| 老虎五行属什么| esse是什么牌子的烟| 大哥是什么生肖| 品牌主理人是什么意思| 灯火葳蕤是什么意思| 清关是什么| 猫咪能看到什么颜色| 世界七大奇迹分别是什么| dg是什么牌子| 可谓是什么意思| 手机暂停服务是什么意思| 暗疾是什么意思| cbd是什么| 湿疹是什么样子的| 石斛配什么泡水喝好| 梦到被猪咬是什么意思| 北齐是什么朝代| mio是什么意思| 指甲油用什么能洗掉| 吃什么会长高| 黄芪长什么样子的图片| 阑尾疼吃什么药| 猫咖是什么| tnt是什么意思| 小兔子吃什么食物| 增加胃动力最好的药是什么药| 早晨5点是什么时辰| 中央电视台台长是什么级别| 三体是什么意思| 祭是什么意思| 高岗为什么自杀| junior什么意思| 平安扣适合什么人戴| 泊字五行属什么| 吃什么呢| 非均匀性脂肪肝是什么意思| 传教士是什么姿势| 蛋白尿是什么症状| 光年是什么单位| 98年的属什么| 越五行属什么| 天秤座是什么星座| 葵水是什么意思| c罗为什么不结婚| 才子男装什么档次| 炒房是什么意思| 怀孕什么时候打胎最合适| 岳飞为什么必须死| 师长是什么意思| 打擦边球是什么意思| 李隆基是李世民的什么人| 女生胸部发育到什么年龄| 杏干泡水喝有什么功效| 血糖高可以吃什么肉类| 变态是什么意思| 肛瘘是什么病| 流口水是什么病| 深圳少年宫有什么好玩的| reebok是什么牌子| 鼻窦炎首选什么抗生素| 镜子是什么生肖| 热惊厥病发是什么症状| 火花塞坏了有什么症状| 小便短赤是什么意思| 三文鱼又叫什么鱼| 肝风上扰会有什么症状| 眼睛发炎用什么药效果好| 全身发烫但不发烧是什么原因| 女人阴虚火旺吃什么药| 赫兹是什么| 8月3号是什么星座| 宝宝打嗝是什么原因引起的| 国帑是什么意思| 干净的什么| 亲戚是什么意思| 青少年手抖是什么原因| 异常的反义词是什么| 经常拉屎是什么原因| 蛇吃什么食物| 5月2日是什么星座| 风湿病挂什么科| 1996年1月属什么生肖| 痰湿瘀阻是什么症状| 什么样的伤口算开放性| 寸是什么单位| 水泥烧伤皮肤用什么药| 2月11日什么星座| 孩子呕吐是什么原因| 螳螂是什么生肖| 刮痧的痧是什么东西| 爱戴是什么意思| 地贫和贫血有什么区别| 青鱼又叫什么鱼| 9.25什么星座| 知府相当于现在什么官| 乳糖不耐受吃什么奶粉好| 下眼睑红肿是什么原因| 吃芥末有什么好处| 18kgp是什么意思| 岔气了吃什么药| 液体套是什么| 坐骨神经痛吃什么药好得快| 甲状腺挂什么科| 甜字五行属什么| 外阴瘙痒擦什么药| 十月初三是什么星座| cea升高是什么意思| 尿急尿频尿不尽吃什么药| 1月16日什么星座| 什么什么归赵| 手汗脚汗多是什么原因| 铁线虫是什么| 巴西货币叫什么| 维生素b2有什么作用| 1996五行属什么| 什么是丁克| 脚底有痣代表什么意思| 帆布是什么材质| 人发胖的原因是什么引起的| 什么车适合女生开| qn是什么意思| 十月十一是什么星座| Mo什么元素| 三亚免税店什么最便宜| 奶酪和芝士有什么区别| 怀孕脸上长痘痘是什么原因| zoe是什么意思| 6月10日什么星座| shit什么意思| 肾痛在什么位置痛| 白莲子和红莲子有什么区别| 突然戒烟对身体有什么影响| com是什么| 流鼻血吃什么药效果好| 争奇斗艳的斗是什么意思| 锦鲤吃什么| 口若悬河是什么生肖| 续航是什么意思| 敬请是什么意思| 什么是抗凝药物| 美满霉素又叫什么名字| 什么的姑娘| 承欢膝下是什么意思| 伤骨头了吃什么好得快| 狼毫毛笔是什么毛| 钟爱一生是什么意思| 胃炎吃什么药好| 四级士官是什么级别| 鱼皮是什么鱼的皮| 什么是疱疹怎么得的| 什么鞋不能穿| 左胸上方隐痛什么原因| 日久见人心是什么意思| 无花果是什么季节的水果| 副军级是什么军衔| lg是什么牌子| 打喷嚏流鼻涕属于什么感冒| 妊娠囊是什么意思| 胎儿宫内窘迫是什么意思| 精华液是干什么的| 大便出血是什么原因引起的| 蛇什么时候出来活动| 百度
blob: 620db813e64557e2e72194c9314fdf948e7cf357 [file] [log] [blame] [edit]
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Fuzz testing for EncodedProgram serialized format and assembly.
//
// We would like some assurance that if an EncodedProgram is malformed we will
// not crash. The EncodedProgram could be malformed either due to malicious
// attack to due to an error in patch generation.
//
// We try a lot of arbitrary modifications to the serialized form and make sure
// that the outcome is not a crash.
#include "courgette/encoded_program.h"
#include <stddef.h>
#include <memory>
#include "base/test/test_suite.h"
#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/courgette_flow.h"
#include "courgette/streams.h"
class DecodeFuzzTest : public BaseTest {
public:
void FuzzExe(const char *) const;
private:
void FuzzByte(const std::string& buffer, const std::string& output,
size_t index) const;
void FuzzBits(const std::string& buffer, const std::string& output,
size_t index, int bits_to_flip) const;
// Returns true if could assemble, false if rejected.
bool TryAssemble(const std::string& buffer, std::string* output) const;
};
// Loads an executable and does fuzz testing in the serialized format.
void DecodeFuzzTest::FuzzExe(const char* file_name) const {
std::string file1 = FileContents(file_name);
const uint8_t* original_data = reinterpret_cast<const uint8_t*>(file1.data());
size_t original_length = file1.length();
courgette::CourgetteFlow flow;
courgette::RegionBuffer original_buffer(
courgette::Region(original_data, original_length));
flow.ReadDisassemblerFromBuffer(flow.ONLY, original_buffer);
EXPECT_EQ(courgette::C_OK, flow.status());
EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->disassembler.get());
flow.CreateAssemblyProgramFromDisassembler(flow.ONLY, false);
EXPECT_EQ(courgette::C_OK, flow.status());
EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->program.get());
flow.CreateEncodedProgramFromDisassemblerAndAssemblyProgram(flow.ONLY);
EXPECT_EQ(courgette::C_OK, flow.status());
EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->encoded.get());
flow.DestroyAssemblyProgram(flow.ONLY);
EXPECT_EQ(courgette::C_OK, flow.status());
EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->program.get());
flow.DestroyDisassembler(flow.ONLY);
EXPECT_EQ(courgette::C_OK, flow.status());
EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->disassembler.get());
flow.WriteSinkStreamSetFromEncodedProgram(flow.ONLY);
EXPECT_EQ(courgette::C_OK, flow.status());
flow.DestroyEncodedProgram(flow.ONLY);
EXPECT_EQ(courgette::C_OK, flow.status());
EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->encoded.get());
courgette::SinkStream sink;
flow.WriteSinkStreamFromSinkStreamSet(flow.ONLY, &sink);
EXPECT_EQ(courgette::C_OK, flow.status());
EXPECT_TRUE(flow.ok());
EXPECT_FALSE(flow.failed());
size_t length = sink.Length();
std::string base_buffer(reinterpret_cast<const char*>(sink.Buffer()), length);
std::string base_output;
bool ok = TryAssemble(base_buffer, &base_output);
EXPECT_TRUE(ok);
// Now we have a good serialized EncodedProgram in |base_buffer|. Time to
// fuzz.
// More intense fuzzing on the first part because it contains more control
// information like substeam lengths.
size_t position = 0;
for ( ; position < 100 && position < length; position += 1) {
FuzzByte(base_buffer, base_output, position);
}
// We would love to fuzz every position, but it takes too long.
for ( ; position < length; position += 900) {
FuzzByte(base_buffer, base_output, position);
}
}
// FuzzByte tries to break the EncodedProgram deserializer and assembler. It
// takes a good serialization of and EncodedProgram, flips some bits, and checks
// that the behaviour is reasonable. It has testing checks for unreasonable
// behaviours.
void DecodeFuzzTest::FuzzByte(const std::string& base_buffer,
const std::string& base_output,
size_t index) const {
printf("Fuzzing position %d\n", static_cast<int>(index));
// The following 10 values are a compromize between run time and coverage of
// the 255 'wrong' values at this byte position.
// 0xFF flips all the bits.
FuzzBits(base_buffer, base_output, index, 0xFF);
// 0x7F flips the most bits without changing Varint32 framing.
FuzzBits(base_buffer, base_output, index, 0x7F);
// These all flip one bit.
FuzzBits(base_buffer, base_output, index, 0x80);
FuzzBits(base_buffer, base_output, index, 0x40);
FuzzBits(base_buffer, base_output, index, 0x20);
FuzzBits(base_buffer, base_output, index, 0x10);
FuzzBits(base_buffer, base_output, index, 0x08);
FuzzBits(base_buffer, base_output, index, 0x04);
FuzzBits(base_buffer, base_output, index, 0x02);
FuzzBits(base_buffer, base_output, index, 0x01);
}
// FuzzBits tries to break the EncodedProgram deserializer and assembler. It
// takes a good serialization of and EncodedProgram, flips some bits, and checks
// that the behaviour is reasonable.
//
// There are EXPECT calls to check for unreasonable behaviour. These are
// somewhat arbitrary in that the parameters cannot easily be derived from first
// principles. They may need updating as the serialized format evolves.
void DecodeFuzzTest::FuzzBits(const std::string& base_buffer,
const std::string& base_output,
size_t index, int bits_to_flip) const {
std::string modified_buffer = base_buffer;
std::string modified_output;
modified_buffer[index] ^= bits_to_flip;
bool ok = TryAssemble(modified_buffer, &modified_output);
if (ok) {
// We normally expect TryAssemble to fail. But sometimes it succeeds.
// What could have happened? We changed one byte in the serialized form:
//
// * If we changed one of the copied bytes, we would see a single byte
// change in the output.
// * If we changed an address table element, all the references to that
// address would be different.
// * If we changed a copy count, we would run out of data in some stream,
// or leave data remaining, so should not be here.
// * If we changed an origin address, it could affect all relocations based
// off that address. If no relocations were based off the address then
// there will be no changes.
// * If we changed an origin address, it could cause some abs32 relocs to
// shift from one page to the next, changing the number and layout of
// blocks in the base relocation table.
// Generated length could vary slightly due to base relocation table layout.
// In the worst case the number of base relocation blocks doubles, approx
// 12/4096 or 0.3% size of file.
size_t base_length = base_output.length();
size_t modified_length = modified_output.length();
ptrdiff_t diff = base_length - modified_length;
if (diff < -200 || diff > 200) {
EXPECT_EQ(base_length, modified_length);
}
size_t changed_byte_count = 0;
for (size_t i = 0; i < base_length && i < modified_length; ++i) {
changed_byte_count += (base_output[i] != modified_output[i]);
}
if (index > 60) { // Beyond the origin addresses ...
EXPECT_NE(0U, changed_byte_count); // ... we expect some difference.
}
// Currently all changes are smaller than this number:
EXPECT_GE(45000U, changed_byte_count);
}
}
bool DecodeFuzzTest::TryAssemble(const std::string& file,
std::string* output) const {
courgette::CourgetteFlow flow;
courgette::RegionBuffer file_buffer(courgette::Region(
reinterpret_cast<const uint8_t*>(file.data()), file.length()));
flow.ReadSourceStreamSetFromBuffer(flow.ONLY, file_buffer);
if (flow.failed())
return false;
flow.ReadEncodedProgramFromSourceStreamSet(flow.ONLY);
if (flow.failed())
return false;
courgette::SinkStream sink;
flow.WriteExecutableFromEncodedProgram(flow.ONLY, &sink);
if (flow.failed())
return false;
output->clear();
output->assign(reinterpret_cast<const char*>(sink.Buffer()), sink.Length());
return true;
}
TEST_F(DecodeFuzzTest, All) {
FuzzExe("setup1.exe");
FuzzExe("elf-32-1.exe");
}
int main(int argc, char** argv) {
return base::TestSuite(argc, argv).Run();
}
明天叫什么日子 慕字五行属什么 什么病不能吃绿豆 scj是什么意思 尿频尿急吃什么药比较好
声线是什么意思 黄热病是什么病 农历3月14日是什么星座 什么是小奶狗 八点是什么时辰
雨中即景什么意思 站着腰疼是什么原因引起的 亲嘴什么感觉 肋膈角锐利是什么意思 贤淑是什么意思
心仪的人是什么意思 长期缺铁性贫血会导致什么后果 一件代发是什么意思 sdeer是什么牌子 槐树什么时候开花
吉士粉是什么东西hcv9jop3ns4r.cn 血糖高喝什么牛奶好hcv8jop6ns7r.cn 血压什么时候量最准确hcv9jop7ns3r.cn 吃什么拉什么是什么原因hcv9jop6ns1r.cn 口坐读什么hanqikai.com
长高吃什么钙片xscnpatent.com 白带黄绿色是什么炎症hcv7jop9ns1r.cn 狗肉配什么菜好吃hcv8jop9ns2r.cn CRL是胎儿的什么意思sanhestory.com 什么炒鸡蛋最好吃hcv9jop2ns6r.cn
披萨用什么面粉hcv9jop4ns8r.cn 新生儿前面头发稀少是什么原因hcv7jop9ns2r.cn 伟哥是什么药hcv8jop7ns5r.cn 藏红花有什么作用和功效cl108k.com 利玛窦什么时候来中国hcv9jop7ns2r.cn
马栗是什么植物hcv8jop4ns2r.cn 为什么十五的月亮十六圆weuuu.com 甲状腺是什么xianpinbao.com 7代表什么hcv9jop5ns5r.cn 小丑什么意思cl108k.com
百度