Skip to content

fix: LRC timestamp rollover, malformed-segment 500s, non-ASCII export crash - #11

Merged
cchacs merged 2 commits into
mainfrom
claude/bug-search-mfyoq0
Sep 8, 2026
Merged

cchacs merged 2 commits into
mainfrom
claude/bug-search-mfyoq0

Conversation

@cchacs

@cchacs cchacs commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • /export raised UnicodeEncodeError (500) for any title/artist containing a character outside Latin-1 (CJK, Cyrillic, emoji, ...) — Starlette encodes Content-Disposition header values as Latin-1, and the legacy filename= fallback was never folded to ASCII. Extracted the fold the lyrics_karaoke plugin already had into _ascii_safe_filename_component() and applied it here too.
  • _format_lrc / _format_lrc_word_level computed minutes/seconds independently (int(t // 60), f"{t % 60:05.2f}"), so a seconds remainder that rounds up to 60.00 under :05.2f (e.g. 59.996) printed an invalid timestamp like [01:60.00] instead of rolling into the next minute. New _lrc_timestamp() rounds to whole centiseconds first, then splits into minutes/seconds, so the carry happens before formatting.
  • Both formatters, and /save's segment-to-lyrics conversion, indexed seg["start"]/seg["text"]/seg["end"] directly, so a malformed segment (missing key, non-numeric start/end, a non-dict entry) raised KeyError/TypeError and 500'd the whole request instead of being skipped (/export) or reported as a clear 400 (/save).

Test plan

  • pytest tests/test_helpers.py — 23 passed (8 new tests covering the rollover, malformed segments, and the ASCII-safe helper)
  • Verified in isolation: 119.999 → 02:00.00 (was 01:60.00); a title with CJK characters no longer raises UnicodeEncodeError when encoded as latin-1

🤖 Generated with Claude Code

https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy


Generated by Claude Code

- /export raised UnicodeEncodeError (500) for any title/artist with a
  character outside Latin-1 (CJK, Cyrillic, emoji, ...), because
  Starlette encodes Content-Disposition header values as Latin-1 and
  the legacy filename= fallback was never folded to ASCII. Extracted
  the fold already used by the karaoke plugin into
  _ascii_safe_filename_component() and applied it here too.
- _format_lrc / _format_lrc_word_level computed minutes/seconds
  independently (int(t // 60), f"{t % 60:05.2f}"), so a seconds
  remainder that rounds up to 60.00 under :05.2f (e.g. 59.996) printed
  an invalid timestamp like [01:60.00] instead of rolling into the next
  minute. New _lrc_timestamp() rounds to whole centiseconds first, then
  splits into minutes/seconds, so the carry happens before formatting.
- Both formatters, and /save's segment-to-lyrics conversion, indexed
  seg["start"]/seg["text"]/seg["end"] directly, so a malformed
  segment (missing key, non-numeric start/end, a non-dict entry) raised
  KeyError/TypeError and 500'd the whole request instead of being
  skipped (/export) or reported as a clear 400 (/save).
- Bumped plugin.json to 1.1.2 (bug fixes affecting real behavior).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 44aa573e-f664-4946-9ec0-b09e6ec9d677

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The three headline fixes are right, well-documented, and covered by genuine regression tests — the rollover, the ASCII fold, and the segment guards all do what the PR claims. One input class still slips through every new guard: values that float() parses to inf/NaN (1e999, "Infinity", "NaN"). Those either 500 /export via an OverflowError inside _lrc_timestamp, or get persisted into lyrics.json as literal Infinity/NaN on /save, which neither the browser frontend nor ls_get_lyrics can read back. Details inline.

Reviewed changes — three bug fixes plus malformed-input hardening, with tests:

  • LRC timestamp rollover — new _lrc_timestamp() rounds to whole centiseconds before splitting minutes/seconds, so 59.996 → 01:00.00 instead of the invalid [01:60.00]; negative values are now clamped to 00:00.00.
  • Non-ASCII export 500 — _ascii_safe_filename_component() folds the legacy filename= Content-Disposition fallback to printable ASCII (Starlette latin-1-encodes header values); the filename*=UTF-8''… form still carries the real name.
  • Malformed-segment hardening — /export skips missing/non-numeric segments and non-dict entries; /save validates every segment up front and returns a clear 400; segments-is-list and title/artist-is-str guards added.
  • Regression tests — 8 new tests in tests/test_helpers.py, each of which fails against the prior implementation (not theatre).

ℹ️ filename*= is never honored by the plugin's own download path

The real filename survives only in the filename*=UTF-8''… part of the header — but lsExport (screen.js:284-286) reads just the legacy filename="(.+)", so a CJK/emoji title still downloads as ____ - Lemon.lrc through the UI. If real filenames matter, lsExport could decodeURIComponent the filename* value instead. Not blocking — strictly better than the pre-PR 500.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Big Pickle (free) | 𝕏

Comment thread routes.py Resolved
Comment thread routes.py Resolved

cchacs commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed this PR (not driving it, just leaving findings).

_lrc_timestamp still crashes on an infinite start value:

total_centis = round(max(0.0, float(t)) * 100)

If seg["start"] is the string "Infinity" or "inf", float(t) succeeds (Python's float() parses those without raising ValueError), so it sails past the try/except (KeyError, TypeError, ValueError) around the conversion. The crash happens one line later, unguarded: round() can't convert inf to an int, so it raises an unhandled OverflowError and 500s the whole export/save.

This is actually pre-existing — the old int(t // 60) had the identical crash on inf — so it's not a regression from this PR. But this PR's own title calls out "malformed-segment 500s" as fixed, and this is exactly that failure mode, still open, in code this PR is already touching.

feedpakr's ws_build hit the same "a finite-looking string that Python's float() happily parses as inf/nan" class of bug for manual_offset and fixed it with an explicit math.isfinite() check — same fix would work here, e.g. in _lrc_timestamp itself so both call sites (and ls_save's validation loop, which has the same gap for the t/d it writes to lyrics.json) are covered by one guard.


Generated by Claude Code

…orrupting

Infinity/NaN (via literal "Infinity"/"nan" or an overflowing literal like
1e999) parsed fine as floats and slipped past every existing malformed-
segment guard:

- /export: _lrc_timestamp's round(inf * 100) raised OverflowError,
  500ing the whole export.
- /save: the same values passed validation and were persisted as literal
  Infinity/NaN in lyrics.json (json.dumps' default allow_nan=True) --
  unreadable by both the frontend's JSON.parse and ls_get_lyrics' own
  allow_nan=False serializer, corrupting the song.

Added math.isfinite checks alongside the existing float() conversions in
_format_lrc, _format_lrc_word_level, and ls_save's /save validation.

Also hardened _format_lrc_word_level against "words": null -- iterating
it directly raised TypeError outside any try/except. Checking
isinstance(seg.get("words"), list) rejects None the same way it already
rejected any other non-list shape.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — since the prior review at 516ab50, commit bd4b088 addresses both of its findings and carries supporting cleanup:

  • Non-finite timestamps now guarded — math.isfinite checks follow the float() conversions in _format_lrc, _format_lrc_word_level (both the segment start and each word's start), and /save's validation loop; non-finite values are skipped on export and rejected with a clear 400 on save, closing the OverflowError 500 and the literal-Infinity/NaN persistence hole in lyrics.json.
  • "words": null no longer 500s word-level formatting — the guard moved from "words" in seg to isinstance(seg.get("words"), list), matching how malformed word entries are already rejected inside the loop.
  • Supporting cleanup — import math lifted to module scope (previously duplicated inside ls_save_lyrics), module docstring added, plugin.json version bumped 1.1.2 → 1.1.3.
  • Regression tests — four new tests cover null words, non-finite segment/word starts, and the 1e999 overflow literal; each fails against the 516ab50 implementation, and the rollover/guarding arithmetic was verified in the sandbox.

Both threads from the prior review were addressed by these commits.

Pullfrog  | View workflow run | Using Big Pickle (free) | 𝕏

@kilo-code-bot

kilo-code-bot Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • routes.py
  • plugin.json
  • tests/test_helpers.py

Reviewed by free · Input: 149.3K · Output: 8.9K · Cached: 82.1K

@cchacs
cchacs merged commit d6e0bc1 into main Sep 8, 2026
5 checks passed
@cchacs
cchacs deleted the claude/bug-search-mfyoq0 branch September 8, 2026 22:59
cchacs pushed a commit that referenced this pull request Sep 9, 2026
…Error

Same latent bug just found and fixed in the lyrics_karaoke plugin's copy
of this code (feedBack-plugin-lyrics-karaoke#9 review): callers gate
_lrc_timestamp() calls on math.isfinite(t), but that alone doesn't catch
a value like 1e307 -- a real, finite double whose *scaled* form
(1e307 * 100 = 1e309) exceeds the max representable double and becomes
inf, so round() on the scaled value raised OverflowError instead of the
clean skip the finiteness check was meant to guarantee.

_lrc_timestamp() now checks the scaled (centisecond) value for
finiteness too, raising ValueError instead of letting round() overflow.
_format_lrc() and _format_lrc_word_level() now catch that ValueError
and skip the segment/word, consistent with their existing malformed-
input handling, rather than letting it propagate as a 500.

This PR (#11) already merged before this bug was found, so this branch
was restarted from main per the merged-PR branch-recovery convention.

Bumped plugin.json to 1.1.4.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy
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.

2 participants