Apply a few improvements and fixes#87
Merged
Merged
Conversation
7e0836c to
fd37889
Compare
There was a problem hiding this comment.
Pull request overview
This PR tightens robustness and safety across several USB recovery/flash protocols and improves CI workflow reliability by preventing hangs, guarding parsing, and reducing resource leaks.
Changes:
- Bound the i.MX SDP DCD “check” loop and raise a timeout instead of potentially hanging forever.
- Harden I/O and parsing paths (HID reads, bmap handling/cleanup, log parsing guards) to avoid crashes and FD leaks.
- Restrict fastboot CLI dispatch to an explicit allowlist and refine GitHub Actions workflow ordering/triggers.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/snagrecover/protocols/imx_sdp.py |
Replace infinite DCD check loop with bounded retries + timeout error. |
src/snagrecover/protocols/hid.py |
Avoid slicing before validating HID read result; fix error message formatting. |
src/snagrecover/protocols/fel.py |
Remove dead/duplicated endpoint direction assignment. |
src/snagrecover/protocols/fastboot.py |
Remove dead/duplicated endpoint direction assignment. |
src/snagflash/ums.py |
Ensure bmap-related files are reliably closed via try/finally; handle clearsigned bmap. |
src/snagflash/fastboot.py |
Add explicit allowlist for fastboot commands before getattr dispatch. |
src/snagfactory/session.py |
Add match is None guards before .groups() when parsing logs. |
src/snagfactory/board.py |
Share a single /dev/null handle for stdout/stderr redirection. |
.github/workflows/main.yml |
Limit push triggers to main, make tests depend on lint, and adjust install step. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The first is_in assignment was identical to is_bulk (checking bmAttributes instead of bEndpointAddress), making it dead code immediately overwritten by the correct check on the next line. Remove the redundant assignment. Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
Replace the unbounded while True loop in _process_dcd_check_data() with a time-based timeout and a small sleep between reads. This ensures the timeout reflects real elapsed time rather than USB transaction count, and gives hardware enough time to satisfy the condition before the loop exits. Then raise TimeoutError if the condition is never met, preventing a hang when the device is unresponsive.
Wrap the copy operation in try/finally to guarantee mapfileb is closed even if an exception is raised. Also explicitly close and clear mapfileb when the bmap file is PGP-signed, before reassigning the variable, to avoid leaking the first handle. Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
pattern.match() returns None when the log line doesn't match the expected format, so calling .groups() on None raises AttributeError. Add explicit None checks for the summary, results, and board log sections that raise a descriptive ValueError. Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
Opening os.devnull twice produced two unclosed file descriptors. Use a single handle shared by both sys.stdout and sys.stderr. Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
pyusb can return an integer on error. Slicing an int with [1:]
raises TypeError before the guard check was ever reached. Store
the raw result first, validate it, then slice.
Also add the missing f prefix on the HIDError message so the
{length + 1} placeholder is evaluated rather than printed literally.
Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
getattr() was called with a user-supplied command name after only a dash-to-underscore substitution, allowing any public method on the Fastboot object to be invoked. Introduce an explicit set of allowed command names and reject unknown ones before dispatching. Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
- Restrict push trigger to main branch to avoid duplicate runs on feature branch pushes when a PR is already open - Add needs, lint to test job so failing lint aborts the matrix early - Remove redundant ruff install from test job (only used in lint job) Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
86c2f1f to
c15d2a3
Compare
Python 3.14 tests currently fail because Kivy isn’t pre‑built for that version. Apply continue‑on‑error to the 3.14 matrix entries so the failures are reported but don’t block the overall workflow. Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
c15d2a3 to
cf2c4cf
Compare
Collaborator
|
Thanks a lot! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.