Skip to content

55 bundled font families roboto opensans cannot be selected by font name silently falls back to helvetica spams libharu errors new - #68

Merged
Cadons merged 10 commits into
mainfrom
55-bundled-font-families-roboto-opensans-cannot-be-selected-by-font_name-silently-falls-back-to-helvetica-spams-libharu-errors-new
Aug 15, 2026
Merged

55 bundled font families roboto opensans cannot be selected by font name silently falls back to helvetica spams libharu errors new#68
Cadons merged 10 commits into
mainfrom
55-bundled-font-families-roboto-opensans-cannot-be-selected-by-font_name-silently-falls-back-to-helvetica-spams-libharu-errors-new

Conversation

@Cadons

@Cadons Cadons commented Aug 15, 2026

Copy link
Copy Markdown
Owner

No description provided.

Cadons and others added 10 commits August 15, 2026 17:16
HPDF_LoadTTFontFromMemory is only present in newer libharu (e.g. Homebrew's
2.4.6); the version vcpkg distributes lacks it, breaking the Windows CI
build. Route through HPDF_LoadTTFontFromFile with a short-lived temp file
instead, which works against any libharu version.
The incrementing-counter temp filename was predictable inside a
world-writable directory, letting a local attacker pre-plant a symlink at
that path and redirect the write (CWE-377/CWE-59). Use an unpredictable
random name and open it with fopen's exclusive-create "x" mode, which
fails instead of following an existing symlink/file.
SonarQube flagged both the raw use of the shared OS temp directory and
the std::mt19937_64/random_device pair used to pick the file name. Drop
the hand-rolled PRNG entirely and delegate name choice + atomic exclusive
creation to the platform primitive (POSIX mkstemp, Windows
O_CREAT|O_EXCL) -- the CERT/OWASP-recommended fix for this CWE-377/CWE-59
pattern. Exclusive creation is what actually blocks the symlink attack;
letting the OS pick an unused name is simpler and no less safe than
generating one ourselves.
The mkstemp/O_CREAT|O_EXCL temp-file logic in DocraftHaruFontBackend was
generic filesystem plumbing unrelated to libharu specifically. Move it
into a DocraftFileUtils helper (write_temp_file/remove_file) so it's
reusable and the font backend only deals with font concerns.
…not-be-selected-by-font_name-silently-falls-back-to-helvetica-spams-libharu-errors-new

# Conflicts:
#	docraft/src/docraft/backend/pdf/docraft_haru_font_backend.cc
write_temp_file wrote directly into the shared system temp root
(/tmp, %TEMP%), which every local user can read and list -- a
publicly-writable-directory info-disclosure/tampering risk flagged
by static analysis (SonarQube rule on temp-file creation) even
though mkstemp/O_EXCL already closed the symlink race. Create a
private, current-user-only (0700) subdirectory via mkdtemp (POSIX)
or _mktemp_s+_mkdir (Windows) first, and write the file inside that
instead. remove_file now also cleans up the now-empty subdirectory
for paths matching that layout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
std::filesystem::permissions(dir, owner_all, replace) was leaving
the freshly-created private subdirectory unwritable to its own
owner under MSVC STL, so the subsequent ofstream open failed and
write_temp_file returned nullopt -- breaking
WriteTempFileWritesExactBytesToAFreshUniqueFile only on Windows CI.
Skip the call there: %TEMP% already resolves to a per-user,
ACL-isolated directory on Windows, so the extra lockdown isn't
needed to begin with.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The actual Windows CI failure was in the test, not in
DocraftFileUtils: std::ifstream in(*path, ...) was left open when
remove_file() ran. Unlike POSIX, where unlinking an open file just
drops the directory entry, Windows can't delete a file while a
handle to it is still open, so the removal silently no-op'd there
and std::filesystem::exists(*path) was still true afterwards.
Closing the handle first fixes it and lets DocraftFileUtils keep a
single, platform-agnostic implementation -- revert the previous
(mistaken) #if !defined(_WIN32) guard around permissions(), which
wasn't the actual cause.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@Cadons
Cadons merged commit bf4e9b2 into main Aug 15, 2026
11 checks passed
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