Repository navigation
fix: LRC timestamp rollover, malformed-segment 500s, non-ASCII export crash - #11
Conversation
- /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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
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, so59.996 → 01:00.00instead of the invalid[01:60.00]; negative values are now clamped to00:00.00. - Non-ASCII export 500 —
_ascii_safe_filename_component()folds the legacyfilename=Content-Disposition fallback to printable ASCII (Starlette latin-1-encodes header values); thefilename*=UTF-8''…form still carries the real name. - Malformed-segment hardening —
/exportskips missing/non-numeric segments and non-dict entries;/savevalidates every segment up front and returns a clear 400;segments-is-list andtitle/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.
Big Pickle (free) | 𝕏
|
Reviewed this PR (not driving it, just leaving findings).
total_centis = round(max(0.0, float(t)) * 100)If This is actually pre-existing — the old
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
There was a problem hiding this comment.
✅ 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.isfinitechecks follow thefloat()conversions in_format_lrc,_format_lrc_word_level(both the segmentstartand each word'sstart), and/save's validation loop; non-finite values are skipped on export and rejected with a clear 400 on save, closing theOverflowError500 and the literal-Infinity/NaNpersistence hole inlyrics.json. "words": nullno longer 500s word-level formatting — the guard moved from"words" in segtoisinstance(seg.get("words"), list), matching how malformed word entries are already rejected inside the loop.- Supporting cleanup —
import mathlifted to module scope (previously duplicated insidels_save_lyrics), module docstring added,plugin.jsonversion bumped1.1.2→1.1.3. - Regression tests — four new tests cover null
words, non-finite segment/word starts, and the1e999overflow literal; each fails against the516ab50implementation, and the rollover/guarding arithmetic was verified in the sandbox.
Both threads from the prior review were addressed by these commits.
Big Pickle (free) | 𝕏
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Reviewed by free · Input: 149.3K · Output: 8.9K · Cached: 82.1K |
…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

Summary
/exportraisedUnicodeEncodeError(500) for any title/artist containing a character outside Latin-1 (CJK, Cyrillic, emoji, ...) — Starlette encodesContent-Dispositionheader values as Latin-1, and the legacyfilename=fallback was never folded to ASCII. Extracted the fold thelyrics_karaokeplugin already had into_ascii_safe_filename_component()and applied it here too._format_lrc/_format_lrc_word_levelcomputed minutes/seconds independently (int(t // 60),f"{t % 60:05.2f}"), so a seconds remainder that rounds up to60.00under: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./save's segment-to-lyrics conversion, indexedseg["start"]/seg["text"]/seg["end"]directly, so a malformed segment (missing key, non-numeric start/end, a non-dict entry) raisedKeyError/TypeErrorand 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)119.999→02:00.00(was01:60.00); a title with CJK characters no longer raisesUnicodeEncodeErrorwhen encoded aslatin-1🤖 Generated with Claude Code
https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy
Generated by Claude Code