From 39ab034d28c6e5ef6a610a9097fa8c95cd286f6a Mon Sep 17 00:00:00 2001 From: Rot127 <45763064+Rot127@users.noreply.github.com> Date: Sat, 27 Jun 2026 10:36:12 +0000 Subject: [PATCH] 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 --- librz/core/canalysis.c | 1 + librz/core/cesil.c | 2 ++ librz/core/disasm.c | 6 +++-- librz/include/rz_analysis.h | 6 +++++ test/db/analysis/mips | 17 +------------- test/db/cmd/cmd_interactive_modes | 37 +++++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/librz/core/canalysis.c b/librz/core/canalysis.c index 59929344df..c0660cd12b 100644 --- a/librz/core/canalysis.c +++ b/librz/core/canalysis.c @@ -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; } diff --git a/librz/core/cesil.c b/librz/core/cesil.c index 9d42f561b0..9eeedf4103 100644 --- a/librz/core/cesil.c +++ b/librz/core/cesil.c @@ -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; } diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 3aa21d18d9..899275621b 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -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; diff --git a/librz/include/rz_analysis.h b/librz/include/rz_analysis.h index 30fa0d125a..f802847044 100644 --- a/librz/include/rz_analysis.h +++ b/librz/include/rz_analysis.h @@ -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); diff --git a/test/db/analysis/mips b/test/db/analysis/mips index be1c803e0d..636d600962 100644 --- a/test/db/analysis/mips +++ b/test/db/analysis/mips @@ -1731,22 +1731,7 @@ EOF EXPECT=< 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