Skip to content

fix: crash bugs in community apps#51

Open
Swissola wants to merge 1 commit into
echo-lalia:mainfrom
Swissola:fix/crash-bugs-community-apps
Open

fix: crash bugs in community apps#51
Swissola wants to merge 1 commit into
echo-lalia:mainfrom
Swissola:fix/crash-bugs-community-apps

Conversation

@Swissola

Copy link
Copy Markdown

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) raises ValueError. Added a len(parts) < 3 guard with continue before 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 and path_list[1] raises IndexError. Added len(path_list) > 1 guard.

timer — empty string IndexError after lstrip (timer.py)

time_value.lstrip("0") is called, then time_value[0] is checked. If the value was "0" (all zeros), lstrip produces "" and [0] raises IndexError. Added a truthiness guard: if time_value and time_value[0] == ".".

RandomScale — ZeroDivisionError + sample accumulation bug (Audio.py)

Two bugs in generateTriangleWave():

  1. When freq == 0, 1/freq and the math.sin call both raise ZeroDivisionError. Added early return with empty bytearray.
  2. sampleList = bytearray((sample, sample)) overwrites the list on every iteration instead of appending. Changed to sampleList += bytearray(...) so samples actually accumulate.

mmlPlay — ZeroDivisionError + octave IndexError (mmlPlay.py)

  1. generate_square_wave() divides by frequency; rests/silence notes with frequency 0 crash. Guard returns a silent buffer early.
  2. get_note_frequency() indexes FREQ_TABLE[note][octave] with no bounds check. An out-of-range octave value (from malformed MML or edge-case parsing) raises IndexError. Clamped to 0..len(FREQ_TABLE['C'])-1.

KanjiReader — bare file seek/read (KanjiReader.py)

fn.seek(idx) and fn.read(100) can raise OSError if the file is on SD card and the card is removed or the file handle is stale. Wrapped in try/except OSError that returns the current position so the caller can continue gracefully.

Test plan

  • Connect: send a raw TCP connection with a blank line — no crash
  • LowPowerClock: run app installed directly (no subdirectory) — no crash in store()
  • timer: type 000 and delete until display shows 0 — no crash
  • RandomScale: trigger a note with frequency 0 — silent, no crash
  • mmlPlay: play MML with a rest (R) note — no crash; play with extreme octave value — no crash
  • KanjiReader: remove SD mid-read — graceful skip, no crash

🤖 Generated with Claude Code

- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant