fix: crash bugs in community apps#51
Open
Swissola wants to merge 1 commit into
Open
Conversation
- Connect/Connect.py: request_line.split() raises ValueError if HTTP request is malformed (<3 tokens); now guards with len(parts) < 3 before unpacking
- LowPowerClock/powermanager.py: path_list[1] raises IndexError when __name__ has no dot (single-component module path); guarded with len(path_list) > 1
- timer/timer.py: lstrip("0") on "0.x" yields ".x", then lstrip on a value that was all zeros yields ""; indexing [0] on empty string raises IndexError; added truthiness guard before the check
- RandomScale/Audio.py: generateTriangleWave() divides by freq and passes freq to sin() — both raise ZeroDivisionError when freq==0; guard returns empty bytearray early. Also fixed sampleList = bytearray(...) to sampleList += bytearray(...) so samples accumulate instead of each iteration discarding all prior work
- mmlPlay/mmlPlay.py: generate_square_wave() divides by frequency — ZeroDivisionError on rests/silence; guard returns silent buffer. get_note_frequency() indexes FREQ_TABLE[note][octave] with no bounds check — out-of-range octave raises IndexError; clamped to valid range
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
Six crash fixes across five community apps, found during code review. All are edge cases with no impact on normal operation.
Connect — malformed HTTP request line (
Connect.py)request_line.split()is unpacked directly into three variables. A malformed or empty request line (fewer than 3 tokens) raisesValueError. Added alen(parts) < 3guard withcontinuebefore unpacking.LowPowerClock — path_list IndexError (
powermanager.py)path_list[1]is accessed before checking its length. When__name__contains no.(single-component module path),split('/')produces a one-element list andpath_list[1]raisesIndexError. Addedlen(path_list) > 1guard.timer — empty string IndexError after lstrip (
timer.py)time_value.lstrip("0")is called, thentime_value[0]is checked. If the value was"0"(all zeros),lstripproduces""and[0]raisesIndexError. Added a truthiness guard:if time_value and time_value[0] == ".".RandomScale — ZeroDivisionError + sample accumulation bug (
Audio.py)Two bugs in
generateTriangleWave():freq == 0,1/freqand themath.sincall both raiseZeroDivisionError. Added early return with emptybytearray.sampleList = bytearray((sample, sample))overwrites the list on every iteration instead of appending. Changed tosampleList += bytearray(...)so samples actually accumulate.mmlPlay — ZeroDivisionError + octave IndexError (
mmlPlay.py)generate_square_wave()divides byfrequency; rests/silence notes with frequency 0 crash. Guard returns a silent buffer early.get_note_frequency()indexesFREQ_TABLE[note][octave]with no bounds check. An out-of-range octave value (from malformed MML or edge-case parsing) raisesIndexError. Clamped to0..len(FREQ_TABLE['C'])-1.KanjiReader — bare file seek/read (
KanjiReader.py)fn.seek(idx)andfn.read(100)can raiseOSErrorif the file is on SD card and the card is removed or the file handle is stale. Wrapped intry/except OSErrorthat returns the current position so the caller can continue gracefully.Test plan
store()000and delete until display shows0— no crashR) note — no crash; play with extreme octave value — no crash🤖 Generated with Claude Code