Skip to content

Commit 5838a9d

Browse files
authored
fix(core): optimize message decode logic (#384)
1 parent a76a5f8 commit 5838a9d

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

core/src/apps/common/signverify.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ def message_digest(coin: CoinInfo, message: bytes) -> bytes:
2929

3030

3131
def is_non_printable(message: str) -> bool:
32-
return any(ord(c) < 32 or ord(c) == 127 for c in message)
32+
allowed_control_chars = {9, 10, 13} # \t, \n, \r
33+
34+
has_disallowed_control = any(
35+
(ord(c) < 32 and ord(c) not in allowed_control_chars) or ord(c) == 127
36+
for c in message
37+
)
38+
39+
has_printable_chars = any(32 <= ord(c) <= 126 for c in message)
40+
41+
return has_disallowed_control or not has_printable_chars
3342

3443

3544
def decode_message(message: bytes) -> str:

core/src/apps/ethereum/layout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async def show_invalid_delegate(ctx: Context) -> None:
153153

154154
def require_confirm_eip7702(
155155
ctx: Context,
156-
authorty_adrr: str,
156+
authorty_addr: str,
157157
delegate_addr: str,
158158
authority_network: str,
159159
amount: int,
@@ -176,7 +176,7 @@ def require_confirm_eip7702(
176176
return confirm_total_eip7702(
177177
ctx,
178178
title,
179-
authorty_adrr,
179+
authorty_addr,
180180
delegate_addr if not is_revoke else None,
181181
format_ethereum_amount(amount, None, chain_id),
182182
str(nonce),

core/src/trezor/lvglui/scrs/template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ class TransactionDetailsEIP7702(TransactionDetailsBase):
10371037
def __init__(
10381038
self,
10391039
title: str,
1040-
authorty_adrr: str,
1040+
authorty_addr: str,
10411041
delegate_addr: str | None,
10421042
value: str,
10431043
nonce: str,
@@ -1054,7 +1054,7 @@ def __init__(
10541054
primary_color,
10551055
icon_path,
10561056
direction_section=(
1057-
(_(i18n_keys.FIELDS_ACCOUNT), authorty_adrr),
1057+
(_(i18n_keys.FIELDS_ACCOUNT), authorty_addr),
10581058
(_(i18n_keys.FIELDS_DELEGATE_TO), delegate_addr),
10591059
),
10601060
more_section=(

core/src/trezor/ui/layouts/lvgl/altcoin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async def confirm_total_ethereum_eip1559(
194194
async def confirm_total_eip7702(
195195
ctx: wire.GenericContext,
196196
title: str,
197-
authorty_adrr: str,
197+
authorty_addr: str,
198198
delegate_addr: str | None,
199199
amount: str,
200200
nonce: str,
@@ -208,7 +208,7 @@ async def confirm_total_eip7702(
208208

209209
screen = TransactionDetailsEIP7702(
210210
title,
211-
authorty_adrr,
211+
authorty_addr,
212212
delegate_addr,
213213
amount,
214214
nonce,

0 commit comments

Comments
 (0)