[PR #1923] fix(mp4): Use fixed-width integer types in bswap functions #2723

Open
opened 2026-01-29 17:23:36 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/1923

State: closed
Merged: Yes


Summary

  • Changes bswap16 and bswap32 to use int16_t and int32_t instead of short and long
  • Ensures consistent NAL unit length parsing across Windows and Linux platforms

Problem

On Windows x64, long is 4 bytes (LLP64 model), while on Linux x64 long is 8 bytes (LP64 model). This type size difference in the bswap32 function could cause inconsistent behavior when parsing NAL unit lengths in MP4/MOV files.

When reading NAL lengths with *(long *)&s->data[i]:

  • Linux x64: Reads 8 bytes from memory
  • Windows x64: Reads 4 bytes from memory

This could potentially affect timestamp calculations and cause the timing differences observed between Windows and Linux CI tests.

Changes

Function Before After
bswap16 short int16_t
bswap32 long int32_t

All call sites in process_avc_sample() and process_hevc_sample() updated accordingly.

Test plan

  • Builds successfully on Linux
  • Verify Windows CI tests pass (particularly timing-related tests)
  • Check if tests 37, 136, 226-230 show improved results

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1923 **State:** closed **Merged:** Yes --- ## Summary - Changes `bswap16` and `bswap32` to use `int16_t` and `int32_t` instead of `short` and `long` - Ensures consistent NAL unit length parsing across Windows and Linux platforms ## Problem On Windows x64, `long` is 4 bytes (LLP64 model), while on Linux x64 `long` is 8 bytes (LP64 model). This type size difference in the `bswap32` function could cause inconsistent behavior when parsing NAL unit lengths in MP4/MOV files. When reading NAL lengths with `*(long *)&s->data[i]`: - **Linux x64**: Reads 8 bytes from memory - **Windows x64**: Reads 4 bytes from memory This could potentially affect timestamp calculations and cause the timing differences observed between Windows and Linux CI tests. ## Changes | Function | Before | After | |----------|--------|-------| | `bswap16` | `short` | `int16_t` | | `bswap32` | `long` | `int32_t` | All call sites in `process_avc_sample()` and `process_hevc_sample()` updated accordingly. ## Test plan - [x] Builds successfully on Linux - [ ] Verify Windows CI tests pass (particularly timing-related tests) - [ ] Check if tests 37, 136, 226-230 show improved results 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:23:36 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2723