From fbd6fd1c4fd8be7ec00d1f12fb73a240e87a9c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mu=C3=B1oz=20Rey?= <108531295+Davmunrey@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:09:26 +0100 Subject: [PATCH] fix(android): reject invoke coverage without site evidence (#10679) The JADX bridge emits or removes direct_invokes and direct_invokes_exhaustive together. A protocol item carrying only the coverage flag reached trace_android_references as a reference that claimed true or false coverage over a null site list, while the coverage summary counted it as unknown. The protocol schema now rejects that combination. Rebased onto current main from morluto/rea#2850. The companion change that removed the null default from the result schema already landed on main. Co-authored-by: LcokHcak <268763621+LcokHcak@users.noreply.github.com> --- src/android/JadxProtocol.ts | 53 +++++++++++++-------- tests/boundary/android/JadxAnalysis.test.ts | 11 +++++ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/android/JadxProtocol.ts b/src/android/JadxProtocol.ts index 50ccbba9b3..a4d3788ca3 100644 --- a/src/android/JadxProtocol.ts +++ b/src/android/JadxProtocol.ts @@ -162,27 +162,38 @@ export const jadxXrefsSchema = z.object({ count, resolve_line: z.literal(false), items: z.array( - z.object({ - kind: z.string(), - name: z.string(), - full_name: z.string(), - containing_class: z.string(), - top_class: z.string(), - def_pos: z.int(), - source_selector: androidMethodSelectorSchema.optional(), - direct_invokes_exhaustive: z.boolean().optional(), - direct_invokes: z - .array( - z.object({ - dex_entry: z.string().min(1), - source_raw_method_id: z.string().min(1), - dex_code_unit_offset: count, - dex_method_index: count, - opcode: z.string().regex(/^INVOKE_/u), - }), - ) - .optional(), - }), + z + .object({ + kind: z.string(), + name: z.string(), + full_name: z.string(), + containing_class: z.string(), + top_class: z.string(), + def_pos: z.int(), + source_selector: androidMethodSelectorSchema.optional(), + direct_invokes_exhaustive: z.boolean().optional(), + direct_invokes: z + .array( + z.object({ + dex_entry: z.string().min(1), + source_raw_method_id: z.string().min(1), + dex_code_unit_offset: count, + dex_method_index: count, + opcode: z.string().regex(/^INVOKE_/u), + }), + ) + .optional(), + }) + // The bridge emits or removes the site list and its coverage together. + .refine( + (item) => + item.direct_invokes_exhaustive === undefined || + item.direct_invokes !== undefined, + { + message: "Invoke coverage requires a direct invoke site list", + path: ["direct_invokes_exhaustive"], + }, + ), ), }); const toolResponse = z diff --git a/tests/boundary/android/JadxAnalysis.test.ts b/tests/boundary/android/JadxAnalysis.test.ts index 3dc9862242..6227364361 100644 --- a/tests/boundary/android/JadxAnalysis.test.ts +++ b/tests/boundary/android/JadxAnalysis.test.ts @@ -925,6 +925,17 @@ it.each([ ).rejects.toThrow(); }); +it.each([true, false])( + "rejects invoke coverage %s without the direct invoke site list", + async (exhaustive) => { + // The bridge always emits the list with its coverage; one without the + // other must not become a reference that claims coverage over no sites. + await expect( + traceWithReference({ direct_invokes_exhaustive: exhaustive }), + ).rejects.toThrow("Invoke coverage requires a direct invoke site list"); + }, +); + it("preserves bounded instruction coverage separately from using-node coverage", async () => { const result = await traceWithReference({ direct_invokes: [invokeSite],