Lift bounded_message_read to module level
What changed, and why it matters
This commit simply moves an existing helper function from inside a method to the top of the same file. The function's behavior and the security limits it enforces are unchanged. There is no security fix or vulnerability introduced.
No action required; this is a non-functional code cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors bounded_read in health_check_microsd_flow.py into a module-level function named bounded_message_read. It still imports MSG_SIGNING_MAX_LENGTH and returns fd.read(MSG_SIGNING_MAX_LENGTH + 1). The call site is updated to use the new module-level name. No logic, constants, or trust boundaries changed.
Changed components
ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.pyInspect captured patch +7 / −6
diff --git a/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py b/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py
index d2b40a8..241df45 100644
--- a/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py
+++ b/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py
@@ -27,6 +27,12 @@ def is_signable(filename, path=None):
return True
+def bounded_message_read(fd):
+ from public_constants import MSG_SIGNING_MAX_LENGTH
+
+ return fd.read(MSG_SIGNING_MAX_LENGTH + 1)
+
+
class HealthCheckMicrosdFlow(Flow):
def __init__(self, context=None, normal_signing=False):
super().__init__(initial_state=self.choose_file, name='HealthCheckMicrosdFlow')
@@ -59,12 +65,7 @@ class HealthCheckMicrosdFlow(Flow):
from pages import ErrorPage
from public_constants import MSG_SIGNING_MAX_LENGTH
- cap = MSG_SIGNING_MAX_LENGTH + 1
-
- def bounded_read(fd):
- return fd.read(cap)
-
- raw = await ReadFileFlow(self.file_path, binary=True, read_fn=bounded_read).run()
+ raw = await ReadFileFlow(self.file_path, binary=True, read_fn=bounded_message_read).run()
if not raw:
self.set_result(False)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.