[FFmpeg-trac] #8138(avcodec:reopened): load of misaligned address in libavcodec/startcode.c
FFmpeg
trac at avcodec.org
Sun Nov 14 13:38:36 EET 2021
#8138: load of misaligned address in libavcodec/startcode.c
------------------------------------+------------------------------------
Reporter: Suhwan | Owner: (none)
Type: defect | Status: reopened
Priority: normal | Component: avcodec
Version: git-master | Resolution:
Keywords: ubsan | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
------------------------------------+------------------------------------
Changes (by trem):
* status: closed => reopened
* resolution: invalid =>
Comment:
I also came across this UBsan complaint and beg to differ that it's a non-
issue:
Per C11 (n1570) 6.3.2.3 p7:
>
> A pointer to an object type may be converted to a pointer to a different
object type.
> If the resulting pointer is not correctly aligned [...] for the
referenced type, the
> behavior is undefined.
>
It does not make a difference if that UB is behind an
`HAVE_FAST_UNALIGNED` define or not. Though it may very well be used to
indicate if it's performance-wise a good idea to do those loads, as FFmpeg
intents.
So we agree that this load is *possible* when that code path is hit, but
the standard still says that it is UB to do through a cast. But
indirection through a memcpy is a cheap way out of this dilemma. I hacked
it up here:
https://godbolt.org/z/b7M4fbrro
Please compare it to the original version here:
https://godbolt.org/z/G1h5hfqfc
And see the assembly is identical, yet no UB is involved. I am willing to
submit a patch (obeying coding / formatting standards) if there is
consensus that this is an issue that should be resolved.
--
Ticket URL: <https://trac.ffmpeg.org/ticket/8138#comment:2>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list