Fix macOS FBX load failure from FreeType bundled-zlib symbol pollution#10967
Closed
shaneszhang wants to merge 1 commit into
Closed
Fix macOS FBX load failure from FreeType bundled-zlib symbol pollution#10967shaneszhang wants to merge 1 commit into
shaneszhang wants to merge 1 commit into
Conversation
5e00774 to
a6659ed
Compare
On macOS, FBX 7.4 binary files whose property arrays are zlib-compressed (e.g. chess_set_2k.fbx) fail to load with a generic "cannot parse file format" error, while uncompressed FBX load fine. Root cause: FreeType 2.12.1 always embeds its own copy of zlib inside ftgzip.c.o (even with FT_DISABLE_ZLIB=TRUE) and exports inflate / inflateInit_ / zcalloc / adler32 etc. as global symbols. When BambuStudio is statically linked, the linker resolves Assimp's inflateInit_ to FreeType's bundled 1.2.12 copy while inflate still binds at runtime to the system libz (1.2.11). The z_stream/state ABI mismatch makes Assimp's FBX binary parser throw "CompressionFailure decompressing this file using gzip.", surfacing as a generic "cannot parse file format" in the UI. Changes: - Add a macOS-only, idempotent post-install step deps/FREETYPE/strip_libfreetype_zlib.sh (wired in through FREETYPE.cmake) that rewrites ftgzip.c.o inside libfreetype.a so the inlined zlib helpers become local symbols while FT_Gzip_Uncompress / FT_Stream_OpenGzip stay externally visible. Handles universal (x86_64 + arm64) archives via lipo per-slice and is idempotent. - Disable Assimp's bundled zlib on macOS (deps/Assimp/Assimp.cmake: ASSIMP_BUILD_ZLIB=OFF) so it builds against the system zlib. Assimp's vendored zlib fails to compile against the modern macOS SDK: its zutil.h takes the classic-Mac branch under TARGET_OS_MAC and does `#define fdopen(fd,mode) NULL`, clobbering the SDK's real fdopen prototype in <stdio.h>. Windows/Linux keep the bundled zlib. Non-macOS platforms are otherwise unaffected.
a6659ed to
14d1a56
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS, FBX 7.4 binary files whose property arrays are zlib-compressed (e.g.
chess_set_2k.fbx) fail to load with a generic "cannot parse file format" error, while uncompressed FBX load fine.Root cause: FreeType 2.12.1 always embeds its own copy of zlib inside
ftgzip.c.o(even withFT_DISABLE_ZLIB=TRUE) and exportsinflate/inflateInit_/zcalloc/adler32etc. as global symbols. When BambuStudio is statically linked, the linker resolves Assimp'sinflateInit_to FreeType's bundled 1.2.12 copy whileinflatestill binds at runtime to the systemlibz(1.2.11). Thez_stream/state ABI mismatch makes Assimp's FBX binary parser throwCompressionFailure decompressing this file using gzip.Fix
Add a macOS-only, idempotent post-install step
deps/FREETYPE/strip_libfreetype_zlib.sh(wired in throughdeps/FREETYPE/FREETYPE.cmake). It rewritesftgzip.c.oinsidelibfreetype.aso the inlined zlib helpers become local symbols, whileFT_Gzip_Uncompress/FT_Stream_OpenGzipstay externally visible. As a result all zlib calls bind consistently to the systemlibz. Non-macOS platforms are unaffected.lipoper-slice.dyld_info -fixupsthat post-patch allinflate*/zlib symbols bind to/usr/lib/libz.1.dylib.Test plan
chess_set_2k.fbxand other zlib-compressed FBX 7.4 binaries load correctly on macOS.if(APPLE)/Darwin).Made with Cursor