Skip to content

Fix unsound pointer-to-long casts that truncate on LLP64#2317

Merged
WyattBlue merged 5 commits into
mainfrom
patch
Jun 16, 2026
Merged

Fix unsound pointer-to-long casts that truncate on LLP64#2317
WyattBlue merged 5 commits into
mainfrom
patch

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

Casting AVFilterContext* to C long truncated the high 32 bits on LLP64 platforms (64-bit Windows), so distinct contexts could collide on the same _context_by_ptr key. Key on size_t instead, which is pointer-width everywhere. Also route object addresses through uintptr_t rather than signed long long in OpaqueContainer.add.

Casting AVFilterContext* to C long truncated the high 32 bits on
LLP64 platforms (64-bit Windows), so distinct contexts could collide
on the same _context_by_ptr key. Key on size_t instead, which is
pointer-width everywhere. Also route object addresses through uintptr_t
rather than signed long long in OpaqueContainer.add.
av_new_packet() and AVPacket.size take int, but size stays size_t for
av_buffer_create(). FFmpeg caps packet sizes at int range, so make the
narrowing explicit to suppress the warning on Windows.
- AudioFrame._init: explicit int cast on _buffer_size -> avcodec_fill_audio_frame (C4267)
- CodecContext: explicit int casts on extradata_size and parser in_size (C4267)
- avcodec.pxd: bit_rate, rc_max_rate, rc_min_rate are int64_t in FFmpeg, not
  int; widen bit_rate setter to match (C4244, also fixes >2^31 truncation)
- avformat.pxd: AVChapter.id is int64_t, not int (C4244, fixes id truncation)
- Container.set_chapters: explicit uint cast on nb_chapters = count (C4244)
- PyIOFile.pos is a file position; declare it int64_t instead of long
  so it doesn't truncate past 2GB on Win64 (C4244 on pos = / += offset)
- pyio_read_gil: explicit int cast on the len(res) return (C4244)
@WyattBlue WyattBlue merged commit 6b84db2 into main Jun 16, 2026
8 checks passed
@WyattBlue WyattBlue deleted the patch branch June 16, 2026 06:31
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