Skip to content

fix: enforce LC_ALL=C locale and sanitize chapter timestamp ordering - #24

Open
niStee wants to merge 1 commit into
synacktraa:masterfrom
niStee:fix/locale-and-chapter-validation
Open

fix: enforce LC_ALL=C locale and sanitize chapter timestamp ordering#24
niStee wants to merge 1 commit into
synacktraa:masterfrom
niStee:fix/locale-and-chapter-validation

Conversation

@niStee

@niStee niStee commented Aug 26, 2026

Copy link
Copy Markdown

Closes #23

Summary

This PR resolves two related bugs encountered during video playback with ani-skip and mpv:

  1. Locale-dependent float parsing failure: On systems with European / non-POSIX locales (e.g. de_DE.UTF-8, fr_FR.UTF-8), printf "%.3f" in ftoi() failed when parsing decimal-dot JSON floats (printf: 151.02: invalid number).
  2. Missing chapter timestamp sanity/order check: Corrupted or out-of-order community timestamps from the API (such as ed_start < op_end) previously produced out-of-order chapter files that caused mpv's ffmpeg demuxer to reject the chapter file with Chapter end time ... before start ... and fail avformat_open_input().

Changes

  • Set export LC_ALL=C: Ensures POSIX-standard decimal float formatting, regex, and string transformations regardless of host locale environment.
  • Sanitize timestamps in build_options():
    • Validates that start_time < end_time for both Opening and Ending intervals.
    • Ensures Ending strictly follows Opening (ed_start >= op_end). If corrupted, the anomalous segment is safely ignored rather than crashing the metadata demuxer.
    • Writes chapters in chronological order (Opening -> Episode -> Ending).

Verification

Tested with LC_ALL=de_DE.UTF-8 across:

  • Normal episodes (e.g. MAL ID 52991 Ep 1): Valid, sequential Opening, Episode, and Ending chapters generated cleanly.
  • Episodes with corrupted ED timestamps (e.g. MAL ID 39551 Ep 1): Inverted ED is safely dropped, Opening skip options and valid metadata are preserved without ffmpeg rejection.

- Enforce LC_ALL=C to ensure POSIX float parsing in ftoi() across European and non-C locales.
- Sanitize chapter start/end timestamps and chronological ordering in build_options() so corrupted or inverted community metadata (e.g. ed_start < op_end) is filtered out rather than generating broken ffmetadata files.
@synacktraa

Copy link
Copy Markdown
Owner

Thanks for the PR, I will test and merge it this weekend.

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.

fix: locale-dependent ftoi() crash on European systems and missing chapter timestamp sanity validation

2 participants