Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails with strict-aliasing violations #146

Closed
eli-schwartz opened this issue Apr 1, 2024 · 5 comments
Closed

Build fails with strict-aliasing violations #146

eli-schwartz opened this issue Apr 1, 2024 · 5 comments

Comments

@eli-schwartz
Copy link

I tried to compile with LTO: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

The -Werror=* flags are important to detect cases where the compiler can try to optimize based on assuming UB cannot happen, and miscompile code that has UB in it. strict-aliasing issues are always bad but LTO can make them even worse.

I got this error:

[8/18] /usr/bin/x86_64-pc-linux-gnu-g++ -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx -isystem /usr/include/Imath  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=gnu++11 -MD -MT lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -MF lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o.d -o lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc
FAILED: lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx -isystem /usr/include/Imath  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=gnu++11 -MD -MT lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -MF lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o.d -o lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc: In static member function ‘static bool ctl::dpx::isnull(float32_t)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc:209:18: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  209 |         return *((uint32_t *)&v)==(uint32_t)-1;
      |                 ~^~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
[9/18] /usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdStdLibMath.cpp
FAILED: lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdStdLibMath.cpp
In file included from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.h:70,
                 from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdStdLibMath.cpp:69:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log10_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:15:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   15 |     return *(float *)(&log10Table[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:22:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   22 |     return *(float *)(&logTable[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
[10/18] /usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.cpp
FAILED: lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.cpp
In file included from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.h:70,
                 from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.cpp:63:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log10_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:15:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   15 |     return *(float *)(&log10Table[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:22:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   22 |     return *(float *)(&logTable[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
ninja: build stopped: subcommand failed.

Downtream report: https://bugs.gentoo.org/926823
Full build log: build.log

@michaeldsmith
Copy link
Collaborator

@eli-schwartz thank you for reporting this issue. I think I have addressed the issue you have reported with PR #147. Please let us know if that PR resolves the issue for you or if you have any other suggestions or input, etc.

@eli-schwartz
Copy link
Author

Thanks. I tried applying the patches from that PR onto the 1.5.3 release and everything compiled fine.

No more commments in particular (though I guess I am a bit surprised that vcpkg hasn't gone and pinned to say an archive.org copy of the tarball for the version they reverted to).

@michaeldsmith
Copy link
Collaborator

thanks - i agree that the vcpkg thing is a surprise. I think the XV backdoor issue will probably take some time to resolve since the bad actor may have been contributing for a while. Wired has a long piece on it here https://www.wired.com/story/xz-backdoor-everything-you-need-to-know/

michaeldsmith added a commit that referenced this issue Apr 3, 2024
* add docker to duplicate reported issue #146

* fix strict-aliasing issue

* disable tiff on github workflow using vcpkg and in vcpkg.json dependencies due to security issue
@eli-schwartz
Copy link
Author

FWIW it may not be as bad as all that. The bad actor has been contributing since 2021 but it's only since the beginning of 2024 or thereabouts that the original author's guard was lowered enough to put these pieces into place. Status updates will be at https://tukaani.org/xz-backdoor/ and indicate we may not have to wait too long...

@michaeldsmith
Copy link
Collaborator

closed by 7133fc2

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

No branches or pull requests

2 participants