Don't print meta items which are not at the current seek. (#6559)

* Don't print meta items which are not at the current seek.

The old code tried (unsuccessfully) to print _any_ meta item _covering_ the seek (ds->at).

There seems to be several bugs getting triggered with that.
One of them giving the behavior of https://github.com/rizinorg/rizin/issues/6556.

If the current seek is in a _data_ region, the disassembler logic doesn't care.
It just assumes that RzAsmOp.size is equivalent to the size of the objects there.
Even though there are only Meta items.

But since some meta items are like 4K bytes, RzAsmOp.size gets
trimmed down.
Anyways, that completely messes up the size calculation (as can be seen in the issue),
and the navigation.
I couldn't figure out where stuff broke.
But the library closes and I have to leave, so I push that.

That "fix" makes it at least behave somewhat consistently.

* Fix leaks

* Fix and add interactive test
This commit is contained in:
Rot127 2026-06-27 10:36:12 +00:00
parent fda8b28d9d
commit 81028bf12f
6 changed files with 51 additions and 18 deletions

View file

@ -5040,6 +5040,7 @@ RZ_IPI void rz_core_analysis_value_pointers(RzCore *core, RzOutputMode mode) {
if (RZ_STR_EQ(arch, "mips")) {
// forbid aav on mips
free(tmp);
return;
}

View file

@ -99,6 +99,7 @@ RZ_API int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_ex
}
rz_cons_break_push(NULL, NULL);
repeat:
rz_analysis_op_fini(&op);
if (rz_cons_is_breaked()) {
RZ_LOG_WARN("core: esil: emulation interrupted at 0x%08" PFMT64x "\n", addr);
return_tail(0);
@ -215,6 +216,7 @@ repeat:
esil->trap = RZ_ANALYSIS_TRAP_EXEC_ERR;
esil->trap_code = addr;
RZ_LOG_INFO("core: ESIL: Trap, trying to execute a branch in a delay slot\n");
rz_analysis_op_fini(&op2);
return_tail(1);
break;
}

View file

@ -3150,7 +3150,6 @@ static bool ds_print_data_type(RzDisasmState *ds, const ut8 *buf, int ib, int si
static bool ds_print_meta_infos(RzDisasmState *ds, ut8 *buf, int len, int idx, int *mi_type) {
bool ret = false;
RzAnalysisMetaItem *fmi;
RzCore *core = ds->core;
if (!ds->asm_meta) {
return false;
@ -3160,7 +3159,7 @@ static bool ds_print_meta_infos(RzDisasmState *ds, ut8 *buf, int len, int idx, i
return false;
}
bool once = true;
fmi = NULL;
RzAnalysisMetaItem *fmi = NULL;
void **it;
rz_pvector_foreach (metas, it) {
RzIntervalNode *node = *it;
@ -3188,6 +3187,9 @@ static bool ds_print_meta_infos(RzDisasmState *ds, ut8 *buf, int len, int idx, i
rz_pvector_foreach (metas, it) {
RzIntervalNode *node = *it;
RzAnalysisMetaItem *mi = node->data;
if (rz_meta_node_start(node) != ds->at) {
continue;
}
ut64 mi_size = rz_meta_node_size(node);
char *out = NULL;
int hexlen;

View file

@ -1863,9 +1863,15 @@ static inline ut64 rz_meta_item_size(ut64 start, ut64 end) {
}
static inline ut64 rz_meta_node_size(RzIntervalNode *node) {
rz_return_val_if_fail(node, 0);
return rz_meta_item_size(node->start, node->end);
}
static inline ut64 rz_meta_node_start(RzIntervalNode *node) {
rz_return_val_if_fail(node, 0);
return node->start;
}
// Set a meta item at addr with the given contents in the current space.
// If there already exists an item with this type and space at addr (regardless of its size) it will be overwritten.
RZ_API bool rz_meta_set(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, ut64 size, const char *str);

View file

@ -1731,22 +1731,7 @@ EOF
EXPECT=<<EOF
; XREFS(69)
;-- data.004350f8:
0x004350f8 hex length=256 delta=40
0x004350f8 0043 0000 0043 5420 0043 396c 0042 0000 .C...CT .C9l.B..
0x00435108 0040 0000 0000 0000 0000 0000 0000 0000 .@..............
0x00435118 0000 0000 0041 ec80 0041 ec70 0041 1608 .....A...A.p.A..
0x00435128 0040 da54 0041 88d4 0041 ec60 0043 5430 .@.T.A...A.`.CT0
0x00435138 0041 c174 0041 d118 0041 ec50 0000 0000 .A.t.A...A.P....
0x00435148 0000 0000 0000 0000 0041 ec40 0041 9908 .........A.@.A..
0x00435158 0041 ec30 0041 b97c 0041 12c4 0041 b1e0 .A.0.A.|.A...A..
0x00435168 0040 d844 0041 ec20 0041 ab98 0041 ec10 .@.D.A. .A...A..
0x00435178 0041 bec4 0041 d4e4 0041 a588 0041 ec00 .A...A...A...A..
0x00435188 0041 9c50 0041 ebf0 0041 ab50 0041 ebe0 .A.P.A...A.P.A..
0x00435198 0041 ebd0 0043 5464 0041 ebc0 0041 ebb0 .A...CTd.A...A..
0x004351a8 0041 8830 0041 b2b4 0041 eba0 0041 a5a8 .A.0.A...A...A..
0x004351b8 0041 b054 0041 eb90 0041 b760 0041 dc20 .A.T.A...A.`.A.
0x004351c8 0041 eb80 0041 de40 .A...A.@
.dword 0x00430000
0x004350f8 .dword 0x00430000
EOF
RUN

View file

@ -180,3 +180,40 @@ Index 0 data 0 0x0 0%
Index 1 data 0 0x100 100%[?25h END
EOF
RUN
NAME=data xrefs outside functions marked as data
FILE=bins/elf/analysis/mipsbe-ip
CMDS=<<EOF
e scr.utf8=false
e scr.color=0
aaa
s 0x4350f8
< q ; Vp
echo END
EOF
EXPECT=<<EOF
[?25l[0x004350f8 [xAdvc]0 90% 115 bins/elf/analysis/mipsbe-ip]> pd $r @ data.004350f8
; XREFS(69)
;-- data.004350f8:
0x004350f8 .dword 0x00430000
; DATA XREF from fcn.004020d0 @ 0x402108
;-- data.004350fc:
0x004350fc .dword 0x00435420 ; section..sdata
; DATA XREF from fcn.004020d0 @ 0x402120
;-- data.00435100:
0x00435100 .dword 0x0043396c ; obj.__DTOR_END
; XREFS(156)
;-- data.00435104:
0x00435104 .dword 0x00420000 ; str.ute_get_ADDRESS___from_ADDRE 
; DATA XREF from sym._init @ 0x402024
; DATA XREF from sym._fini @ 0x41ecd0
;-- data.00435108:
0x00435108 .dword 0x00400000 ; segment.LOAD0 ; segment.ehdr
0x0043510c .dword 0x00000000
0x00435110 .dword 0x00000000
0x00435114 .dword 0x00000000
0x00435118 .dword 0x00000000
; DATA XREF from fcn.00414700 @ +0xbb0
; DATA XREF from sym.rtnl_open_byproto @ 0x41a878 0.0%[?25h END
EOF
RUN