fix bug when 1-byte opcode will trigger size-limit because of unnecessary bounds check

This commit is contained in:
mykola2312 2024-08-19 08:48:30 +03:00
parent 97c8476d2a
commit bd6682a61d
3 changed files with 10 additions and 4 deletions

View file

@ -312,12 +312,16 @@ int rtdisasm_analyze_single(const uint8_t* code, unsigned size, const instructio
if (type == INSTRUCTION_STD) if (type == INSTRUCTION_STD)
{ {
if (ins->config.has_imm) if (ins->config.has_imm)
{
cur += imm2length(ins->std.imm); cur += imm2length(ins->std.imm);
else if (ins->config.has_value)
cur += value2length(ins->std.value);
if (cur >= end) return -1; if (cur >= end) return -1;
} }
else if (ins->config.has_value)
{
cur += value2length(ins->std.value);
if (cur >= end) return -1;
}
}
// set found // set found
if (found) *found = ins; if (found) *found = ins;

View file

@ -7,8 +7,9 @@ extern void test_1_end();
int main() int main()
{ {
size_t size = (uintptr_t)test_1_end - (uintptr_t)test_1; size_t size = (uintptr_t)test_1_end - (uintptr_t)test_1;
int len = rtdisasm_analyze_single((const uint8_t*)test_1, size, NULL); printf("size %lu\n", size);
printf("rtdisasm_analyze_single: len %d\n", len); // int len = rtdisasm_analyze_single((const uint8_t*)test_1, size, NULL);
// printf("rtdisasm_analyze_single: len %d\n", len);
int offset = rtdisasm_find_target((const uint8_t*)test_1, size, RT_TARGET_NOP); int offset = rtdisasm_find_target((const uint8_t*)test_1, size, RT_TARGET_NOP);
printf("rtdisasm_find_target: offset %d\n", offset); printf("rtdisasm_find_target: offset %d\n", offset);

View file

@ -3,6 +3,7 @@
.globl test_1_end .globl test_1_end
test_1: test_1:
push %rax
push (%rbp) push (%rbp)
nop # target that rtdisasm must reach nop # target that rtdisasm must reach