From 06d1e4cecdd369efc09ae1aa2ee3516953bdf5ab Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Thu, 19 Nov 2026 21:31:53 +0800 Subject: [PATCH] fix(android): accept CR line endings in mapping files (#12346) Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> --- src/domain/android/proguardMapping.test.ts | 16 ++++++++++++++++ src/domain/android/proguardMapping.ts | 16 +++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/domain/android/proguardMapping.test.ts b/src/domain/android/proguardMapping.test.ts index 01f2df4ac9..cb14ba4b0f 100644 --- a/src/domain/android/proguardMapping.test.ts +++ b/src/domain/android/proguardMapping.test.ts @@ -63,6 +63,22 @@ const method = ( return_type = "void", ) => ({ class: `${app}.LoginActivity`, name, return_type, parameter_types }); +it.each([ + ["CR", ["\r"]], + ["CRLF", ["\r\n"]], + ["mixed", ["\r\n", "\r", "\n"]], +] as const)( + "preserves mappings and diagnostics with %s line endings", + (_label, endings) => { + let line = 0; + const text = fixture.replaceAll( + "\n", + () => endings[line++ % endings.length]!, + ); + expect(parse(text)).toEqual(mapping); + }, +); + it("reports header facts, valid record counts and malformed line samples", () => { expect(mapping.reported).toEqual({ compiler: "R8", diff --git a/src/domain/android/proguardMapping.ts b/src/domain/android/proguardMapping.ts index 46c1f6371b..aa5ce1618c 100644 --- a/src/domain/android/proguardMapping.ts +++ b/src/domain/android/proguardMapping.ts @@ -752,13 +752,19 @@ export const parseProguardMapping = ( if (state.indexBytes > state.limits.indexBytes) capacity(state, "index"); if (state.headerBytes > state.limits.projectionBytes) capacity(state, "projection"); + // R8’s BufferedReader-based mapping reader treats CR, LF, and CRLF as + // one line ending each. Find boundaries incrementally to keep memory bounded. + const lineEnd = /\r\n?|\n/gu; let start = 0; while (start <= text.length && state.failure === undefined) { - const newline = text.indexOf("\n", start); - const end = newline < 0 ? text.length : newline; - parseLine(state, text.slice(start, end), state.line); - if (newline < 0) break; - start = newline + 1; + const newline = lineEnd.exec(text); + parseLine( + state, + text.slice(start, newline?.index ?? text.length), + state.line, + ); + if (newline === null) break; + start = lineEnd.lastIndex; state.line++; } if (state.failure !== undefined) return err(state.failure);