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



No description provided.