Skip to content

Fix macOS FBX load failure from FreeType bundled-zlib symbol pollution#10967

Closed
shaneszhang wants to merge 1 commit into
bambulab:masterfrom
shaneszhang:fix/macos-freetype-zlib-fbx
Closed

Fix macOS FBX load failure from FreeType bundled-zlib symbol pollution#10967
shaneszhang wants to merge 1 commit into
bambulab:masterfrom
shaneszhang:fix/macos-freetype-zlib-fbx

Conversation

@shaneszhang
Copy link
Copy Markdown
Contributor

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 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.

Fix

Add a macOS-only, idempotent post-install step deps/FREETYPE/strip_libfreetype_zlib.sh (wired in through deps/FREETYPE/FREETYPE.cmake). It 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. As a result all zlib calls bind consistently to the system libz. Non-macOS platforms are unaffected.

  • Handles universal (x86_64 + arm64) archives via lipo per-slice.
  • Idempotent: re-running on an already-patched archive is a no-op.
  • Verified with dyld_info -fixups that post-patch all inflate*/zlib symbols bind to /usr/lib/libz.1.dylib.

Test plan

  • chess_set_2k.fbx and other zlib-compressed FBX 7.4 binaries load correctly on macOS.
  • Uncompressed FBX and other model formats unaffected.
  • Non-macOS builds unchanged (step is guarded by if(APPLE) / Darwin).

Made with Cursor

@shaneszhang shaneszhang force-pushed the fix/macos-freetype-zlib-fbx branch 2 times, most recently from 5e00774 to a6659ed Compare June 3, 2026 11:54
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.
@shaneszhang shaneszhang force-pushed the fix/macos-freetype-zlib-fbx branch from a6659ed to 14d1a56 Compare June 3, 2026 12:13
@BambulabRobot BambulabRobot requested a review from MackBambu June 4, 2026 08:54
@shaneszhang shaneszhang closed this Jun 4, 2026
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