From d5781c6e0a512234d531d94d1353de2301c2f2da Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Tue, 21 Apr 2026 12:50:49 +0300 Subject: [PATCH 01/12] fix(ooxml): generate GUIDs and random ids from a CSPRNG GenerateGuid and GenerateInt now read from a mutex-guarded CryptoPP AutoSeededRandomPool instead of rand() seeded with time(). Each GUID group now takes 16 random bits instead of 8. Upstream-Subject: fix bug #81148 (cherry picked from commit d9d7ffef2619aa76b8f343d05ad34ecaf652c53a) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- OOXML/Base/Unit.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/OOXML/Base/Unit.cpp b/OOXML/Base/Unit.cpp index 0f71fb0f13..5289f5f03e 100644 --- a/OOXML/Base/Unit.cpp +++ b/OOXML/Base/Unit.cpp @@ -39,7 +39,8 @@ */ #include "Unit.h" #include - +#include +#include "../../Common/3dParty/cryptopp/osrng.h" double Cm_To_Mm (const double &dValue) { @@ -770,30 +771,36 @@ namespace XmlUtils } return std::rand(); } + static unsigned int Rand1() + { + static CryptoPP::AutoSeededRandomPool prng; + static std::mutex prng_mutex; + unsigned int result; + std::lock_guard lock(prng_mutex); + prng.GenerateBlock(reinterpret_cast(&result), sizeof(result)); + return result; + } int GenerateInt() { - //todo c++11 - return ((Rand() & 0x7FFF) | ((Rand() & 0x7FFF) << 15) | ((Rand() & 0x3) << 30)); + return static_cast(Rand1()); } std::wstring GenerateGuid() { std::wstring result; - //#if defined (_WIN32) || defined(_WIN64) - // GUID guid; - // CoCreateGuid(&guid); - // - // OLECHAR* guidString; - // StringFromCLSID(guid, &guidString); - // - // result = std::wstring(guidString); - // - // CoTaskMemFree(guidString); - //#else + std::wstringstream sstream; - sstream << boost::wformat(L"%04X%04X-%04X-%04X-%04X-%04X%04X%04X") % (Rand() & 0xff) % (Rand() & 0xff) % (Rand() & 0xff) % ((Rand() & 0x0fff) | 0x4000) % ((Rand() % 0x3fff) + 0x8000) % (Rand() & 0xff) % (Rand() & 0xff) % (Rand() & 0xff); + sstream << boost::wformat(L"%04X%04X-%04X-%04X-%04X-%04X%04X%04X") + % (Rand1() & 0xffff) + % (Rand1() & 0xffff) + % (Rand1() & 0xffff) + % ((Rand1() & 0x0fff) | 0x4000) + % ((Rand1() & 0x3fff) | 0x8000) + % (Rand1() & 0xffff) + % (Rand1() & 0xffff) + % (Rand1() & 0xffff); result = sstream.str(); - //#endif + return result; } std::wstring DoubleToString( double value, wchar_t* format ) From 36ee2ae7b56cb56a524a4a10cec5374dabb4e1db Mon Sep 17 00:00:00 2001 From: "Oleg.Korshul" Date: Tue, 21 Apr 2026 16:06:19 +0300 Subject: [PATCH 02/12] build(starmath): link CryptoPP into StarMath2OOXML StarMath2OOXML builds Unit.cpp, which now needs CryptoPP. Follow-up to fix(ooxml): generate GUIDs and random ids from a CSPRNG Upstream-Subject: Fix build (cherry picked from commit c03fd25b6dc9a3caaff2ab5df5a5e7bda8c6cf68) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro index 33df4b7d4f..c99fa98c12 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro @@ -49,6 +49,7 @@ include($$CORE_ROOT_DIR/Common/base.pri) include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri) include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri) +LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib ADD_DEPENDENCY(kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ From 4c9b7cd650db7e54706b4897e11322c1af4592f2 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Thu, 23 Apr 2026 10:41:30 +0300 Subject: [PATCH 03/12] fix(xls): check ActiveX control position and size separately Compare lPosInCtlStm and cbBufInCtlStm one at a time against the control stream size before the control data is written, instead of comparing their sum. Upstream-Subject: fix bug #81040 (cherry picked from commit bd3dd15a4ff50b84a58a42cae7cd61464a059b4e) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- MsBinaryFile/XlsFile/Converter/XlsConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MsBinaryFile/XlsFile/Converter/XlsConverter.cpp b/MsBinaryFile/XlsFile/Converter/XlsConverter.cpp index 722c515a4f..71ce26fbcb 100644 --- a/MsBinaryFile/XlsFile/Converter/XlsConverter.cpp +++ b/MsBinaryFile/XlsFile/Converter/XlsConverter.cpp @@ -2522,7 +2522,7 @@ void XlsConverter::convert(XLS::Obj * obj) std::wstring objectId_bin = xlsx_context->get_mediaitems().add_control_activeX(target_bin); NSFile::CFileBinary file; - if(xls_global_info->controls_data.second >= obj->pictFmla.lPosInCtlStm + obj->pictFmla.cbBufInCtlStm) + if (obj->pictFmla.lPosInCtlStm <= xls_global_info->controls_data.second && obj->pictFmla.cbBufInCtlStm <= xls_global_info->controls_data.second - obj->pictFmla.lPosInCtlStm) { if ( file.CreateFileW(xlsx_context->get_mediaitems().activeX_path() + target_bin) ) { From d4861052bd905fe071bbd6499d0fcc315cd4819f Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Fri, 24 Apr 2026 11:10:57 +0300 Subject: [PATCH 04/12] build(cryptopp): disable CryptoPP asm in OFD, DocxFormat and StarMath Build the CryptoPP headers without inline assembly in the projects that compile Unit.cpp. Follow-up to fix(ooxml): generate GUIDs and random ids from a CSPRNG Upstream-Subject: fix bug #81216 (cherry picked from commit 99b31a46f7dead8ded4eb091a7c2584d848f92c1) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- OFDFile/OFDFile.pro | 3 ++- OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro | 3 ++- OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/OFDFile/OFDFile.pro b/OFDFile/OFDFile.pro index 56ef2fa41e..476d3602f6 100644 --- a/OFDFile/OFDFile.pro +++ b/OFDFile/OFDFile.pro @@ -49,7 +49,8 @@ PWD_ROOT_DIR = $$PWD include($$CORE_ROOT_DIR/Common/base.pri) include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri) -DEFINES += OFD_USE_DYNAMIC_LIBRARY +DEFINES += OFD_USE_DYNAMIC_LIBRARY \ + CRYPTOPP_DISABLE_ASM ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, PdfFile) diff --git a/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro b/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro index ee2dac147b..2ccf9a08b1 100644 --- a/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro +++ b/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro @@ -47,7 +47,8 @@ CONFIG += core_x2t include(../../../../Common/base.pri) DEFINES += UNICODE _UNICODE \ - DONT_WRITE_EMBEDDED_FONTS + DONT_WRITE_EMBEDDED_FONTS \ + CRYPTOPP_DISABLE_ASM #BOOST include($$PWD/../../../../Common/3dParty/boost/boost.pri) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro index c99fa98c12..1af216437b 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro @@ -43,7 +43,8 @@ CONFIG += plugin CORE_ROOT_DIR = $$PWD/../../../.. PWD_ROOT_DIR = $$PWD -DEFINES += STARMATH_USE_DYNAMIC_LIBRARY +DEFINES += STARMATH_USE_DYNAMIC_LIBRARY \ + CRYPTOPP_DISABLE_ASM include($$CORE_ROOT_DIR/Common/base.pri) include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri) From 542fe4992b2853ecf57d8fa46d6d776b2d67223a Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Fri, 24 Apr 2026 16:48:47 +0300 Subject: [PATCH 05/12] fix(xlsx): escape userId in threaded comment persons Write the person userId attribute XML-escaped, like displayName and providerId already are. Upstream-Subject: fix bug #81241 (cherry picked from commit 2deb6b8c428c2eb18ccea8a0c3497f23be039dca) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- OOXML/XlsxFormat/Comments/ThreadedComments.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OOXML/XlsxFormat/Comments/ThreadedComments.cpp b/OOXML/XlsxFormat/Comments/ThreadedComments.cpp index 0daefc1061..936ca598b6 100644 --- a/OOXML/XlsxFormat/Comments/ThreadedComments.cpp +++ b/OOXML/XlsxFormat/Comments/ThreadedComments.cpp @@ -67,7 +67,7 @@ namespace OOX writer.WriteString(L""); } From 2ae472399bb8d4c331649b0203f06483a66e51f7 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 24 Apr 2026 17:42:29 +0300 Subject: [PATCH 06/12] fix(pdf): take the CFF random operator value from a CSPRNG FontOTWriter's Type 2 charstring random operator now reads from a mutex-guarded CryptoPP pool instead of rand(). Upstream-Subject: Fix bug 81148 (cherry picked from commit 2761614b8d73a4db434b611420850a8c0ba09f7a) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- PdfFile/SrcWriter/FontOTWriter.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/PdfFile/SrcWriter/FontOTWriter.cpp b/PdfFile/SrcWriter/FontOTWriter.cpp index 3d661a434b..1d668e01f6 100644 --- a/PdfFile/SrcWriter/FontOTWriter.cpp +++ b/PdfFile/SrcWriter/FontOTWriter.cpp @@ -44,8 +44,20 @@ #include #include +#include +#include "../../Common/3dParty/cryptopp/osrng.h" + namespace PdfWriter { + static unsigned int Rand1() + { + static CryptoPP::AutoSeededRandomPool prng; + static std::mutex prng_mutex; + unsigned int result; + std::lock_guard lock(prng_mutex); + prng.GenerateBlock(reinterpret_cast(&result), sizeof(result)); + return result; + } #define N_STD_STRINGS 391 static const char* scStandardStrings[N_STD_STRINGS] = { ".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft", @@ -3677,7 +3689,7 @@ namespace PdfWriter CharStringOperand newOperand; newOperand.IsInteger = false; - newOperand.RealValue = ((double)rand() + 1) / ((double)RAND_MAX + 1); + newOperand.RealValue = ((double)Rand1() + 1) / ((double)RAND_MAX + 1); mOperandStack.push_back(newOperand); return inProgramCounter; From c73d9399b09081e8a4a9bcdad0bdfa29c506bc07 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Mon, 27 Apr 2026 18:12:54 +0300 Subject: [PATCH 07/12] fix(common): size the temp file name buffer to the path CreateTempFileWithUniqueName lets the UTF-8 converter allocate the mkstemp template instead of using a fixed MAX_PATH buffer, and returns an empty string when the name can't be built or GetTempFileNameW fails. Upstream-Subject: Fix bug 81149 (cherry picked from commit 5b15d9b77b2170140ef2af6cc30f24651e73d970) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- DesktopEditor/common/File.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/DesktopEditor/common/File.cpp b/DesktopEditor/common/File.cpp index 176b97b53f..c05f2a65af 100644 --- a/DesktopEditor/common/File.cpp +++ b/DesktopEditor/common/File.cpp @@ -1591,25 +1591,31 @@ namespace NSFile std::wstring CFileBinary::CreateTempFileWithUniqueName(const std::wstring& strFolderPathRoot, const std::wstring& Prefix) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) - wchar_t pBuffer[MAX_PATH + 1]; - ::GetTempFileNameW(strFolderPathRoot.c_str(), Prefix.c_str(), 0, pBuffer); - std::wstring sRet(pBuffer); - return sRet; + wchar_t pBuffer[MAX_PATH + 1] = {0}; + if (0 == ::GetTempFileNameW(strFolderPathRoot.c_str(), Prefix.c_str(), 0, pBuffer)) + return std::wstring(); + return std::wstring(pBuffer); #else - char pcRes[MAX_PATH]; - BYTE* pData = (BYTE*)pcRes; - std::wstring sPrefix = strFolderPathRoot + L"/" + Prefix + L"_XXXXXX"; + LONG lLen = 0; - NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sPrefix.c_str(), (LONG)sPrefix.length(), pData, lLen); - pcRes[lLen] = '\0'; + BYTE* pcRes = NULL; + NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sPrefix.c_str(), (LONG)sPrefix.length(), pcRes, lLen); - int res = mkstemp(pcRes); + if (lLen <= 0) + { + delete[] pcRes; + return std::wstring(); + } + + int res = mkstemp((char*)pcRes); if (-1 != res) close(res); - std::string sRes = pcRes; - return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sRes.c_str(), sRes.length()); + std::wstring sResult = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)pcRes, (LONG)lLen); + + delete[] pcRes; + return sResult; #endif } bool CFileBinary::OpenTempFile(std::wstring *pwsName, FILE **ppFile, wchar_t *wsMode, wchar_t *wsExt, wchar_t *wsFolder, wchar_t* /*wsName*/) From 2ee75b6f5b6f4e52221900b98a5fff8ae6dcea81 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Tue, 28 Apr 2026 18:11:51 +0300 Subject: [PATCH 08/12] refactor(ooxml): use OS random sources instead of CryptoPP Add OOXML/Base/Rand.h with SecureRandomBytes and RandUInt (BCryptGenRandom or RtlGenRandom, SecRandomCopyBytes, getrandom, then /dev/urandom and std::random_device). Unit.cpp uses RandUInt and drops the CryptoPP pool and the old Rand() helper. Follow-up to fix(ooxml): generate GUIDs and random ids from a CSPRNG Conflict: OOXML/Base/Unit.cpp: took upstream's removal of Rand() and Rand1() over our nullptr cleanup Upstream-Subject: Add security rand function (cherry picked from commit 71a8a22d2e4388bad12a52608b37b27344d695ef) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- OOXML/Base/Rand.h | 165 ++++++++++++++++++++++++++++++++++++++++++++ OOXML/Base/Unit.cpp | 40 +++-------- 2 files changed, 175 insertions(+), 30 deletions(-) create mode 100644 OOXML/Base/Rand.h diff --git a/OOXML/Base/Rand.h b/OOXML/Base/Rand.h new file mode 100644 index 0000000000..d05d7a232c --- /dev/null +++ b/OOXML/Base/Rand.h @@ -0,0 +1,165 @@ +#ifndef SECURE_RANDOM_BYTES_H +#define SECURE_RANDOM_BYTES_H + +#include +#include +#include +#include +#include + +#if defined(_WIN32) || defined(_WIN64) +#include + +#if defined(WIN_XP_OR_VISTA) + +// RtlGenRandom (a.k.a. SystemFunction036 in advapi32.dll). +// Available since Windows XP, cryptographically secure, +// does not open key containers — stable under load. +extern "C" BOOLEAN NTAPI SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength); +#pragma comment(lib, "advapi32.lib") + +#else + +#include +#pragma comment(lib, "bcrypt.lib") +#endif + +#elif defined(_MAC) + +#include + +#elif defined(_LINUX) + +#include +#include +#include + +// Fallback syscall numbers for systems where SYS_getrandom is not in headers. +// getrandom() syscall added in Linux 3.17 (October 2014). + +#ifndef SYS_getrandom + +#if defined(__x86_64__) +#define SYS_getrandom 318 +#elif defined(__i386__) +#define SYS_getrandom 355 +#elif defined(__aarch64__) +#define SYS_getrandom 278 +#elif defined(__arm__) +#define SYS_getrandom 384 +#elif defined(__powerpc64__) +#define SYS_getrandom 359 +#elif defined(__riscv) +#define SYS_getrandom 278 +#endif + +#endif + +#endif + + +// Fills `buf` with `len` cryptographically secure random bytes. +// Returns true on success, false if every available source failed. +static bool SecureRandomBytes(unsigned char* buf, size_t len) +{ + if (len == 0) + return true; + if (buf == nullptr) + return false; + + size_t filled = 0; + +#if defined(_WIN32) || defined(_WIN64) + +#if defined(WIN_XP_OR_VISTA) + while (filled < len) + { + ULONG chunk = (len - filled > 0xFFFFFF00u) ? 0xFFFFFF00u : static_cast(len - filled); + if (!::SystemFunction036(buf + filled, chunk)) + break; + filled += chunk; + } + if (filled == len) + return true; +#else + while (filled < len) + { + ULONG chunk = (len - filled > 0xFFFFFF00u) ? 0xFFFFFF00u : static_cast(len - filled); + NTSTATUS status = ::BCryptGenRandom(nullptr, buf + filled, chunk, BCRYPT_USE_SYSTEM_PREFERRED_RNG); + if (status != 0) // STATUS_SUCCESS + break; + filled += chunk; + } + if (filled == len) + return true; +#endif + +#elif defined(_MAC) + if (::SecRandomCopyBytes(kSecRandomDefault, len, buf) == errSecSuccess) + return true; + +#elif defined(__ANDROID__) || defined(__linux__) + // ===== Linux / Android ===== + // Direct syscall — does not depend on glibc version or headers. + // On kernels older than 3.17 syscall returns ENOSYS and we fall through. +#ifdef SYS_getrandom + while (filled < len) { + size_t chunk = (len - filled > 256) ? 256 : (len - filled); + long ret = ::syscall(SYS_getrandom, buf + filled, chunk, 0); + if (ret < 0) { + if (errno == EINTR) continue; + break; // ENOSYS or other error — fall through to /dev/urandom + } + filled += static_cast(ret); + } + if (filled == len) return true; +#endif +#endif + + // POSIX fallback: /dev/urandom +#if !defined(_WIN32) && !defined(_WIN64) + { + FILE* f = std::fopen("/dev/urandom", "rb"); + if (f) { + while (filled < len) { + size_t n = std::fread(buf + filled, 1, len - filled, f); + if (n == 0) break; + filled += n; + } + std::fclose(f); + if (filled == len) return true; + } + } +#endif + + // Final fallback: std::random_device + try + { + static std::mutex m; + static std::random_device rd; + std::lock_guard lock(m); + while (filled < len) + { + unsigned int r = rd(); + size_t to_copy = (len - filled < sizeof(r)) ? (len - filled) : sizeof(r); + std::memcpy(buf + filled, &r, to_copy); + filled += to_copy; + } + return true; + } + catch (...) { + return false; + } + + return false; +} + +// Returns a cryptographically secure random unsigned int. +static unsigned int RandUInt() +{ + unsigned int result = 0; + SecureRandomBytes(reinterpret_cast(&result), sizeof(result)); + return result; +} + +#endif // SECURE_RANDOM_BYTES_H diff --git a/OOXML/Base/Unit.cpp b/OOXML/Base/Unit.cpp index 5289f5f03e..0771574fe8 100644 --- a/OOXML/Base/Unit.cpp +++ b/OOXML/Base/Unit.cpp @@ -40,7 +40,7 @@ #include "Unit.h" #include #include -#include "../../Common/3dParty/cryptopp/osrng.h" +#include "./Rand.h" double Cm_To_Mm (const double &dValue) { @@ -760,29 +760,9 @@ namespace XmlUtils return sstream.str(); } - int Rand() - { - //rand returns integral value range between 0 and RAND_MAX.(RAND_MAX at least 32767.) - static bool init = false; /* ensure different random header each time */ - if (!init) - { - init = true; - srand((unsigned int) time(nullptr)); - } - return std::rand(); - } - static unsigned int Rand1() - { - static CryptoPP::AutoSeededRandomPool prng; - static std::mutex prng_mutex; - unsigned int result; - std::lock_guard lock(prng_mutex); - prng.GenerateBlock(reinterpret_cast(&result), sizeof(result)); - return result; - } int GenerateInt() { - return static_cast(Rand1()); + return static_cast(RandUInt()); } std::wstring GenerateGuid() @@ -791,14 +771,14 @@ namespace XmlUtils std::wstringstream sstream; sstream << boost::wformat(L"%04X%04X-%04X-%04X-%04X-%04X%04X%04X") - % (Rand1() & 0xffff) - % (Rand1() & 0xffff) - % (Rand1() & 0xffff) - % ((Rand1() & 0x0fff) | 0x4000) - % ((Rand1() & 0x3fff) | 0x8000) - % (Rand1() & 0xffff) - % (Rand1() & 0xffff) - % (Rand1() & 0xffff); + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff) + % ((RandUInt() & 0x0fff) | 0x4000) + % ((RandUInt() & 0x3fff) | 0x8000) + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff); result = sstream.str(); return result; From 7c3263b828fb2f6f5e4c899397ed0294a5dfe90d Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Thu, 19 Nov 2026 23:19:41 +0100 Subject: [PATCH 09/12] chore(license): add upstream's header to OOXML/Base/Rand.h Upstream added Rand.h after 9.3, so the licence branch removed it and the pick above brought it back without a header. Apply the Rand.h hunk of upstream's header commit. OOXML/Base/Rand.h only Upstream-Subject: [copyright] Update copyright header (cherry picked from commit 76ee07f61cb917eb313577aed1f9a13f697a5449) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- OOXML/Base/Rand.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/OOXML/Base/Rand.h b/OOXML/Base/Rand.h index d05d7a232c..eadca684e9 100644 --- a/OOXML/Base/Rand.h +++ b/OOXML/Base/Rand.h @@ -1,3 +1,38 @@ +/* + * Copyright (C) Ascensio System SIA, 2009-2026 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation, together with the + * additional terms provided in the LICENSE file. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: https://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA by email at info@onlyoffice.com + * or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga, + * LV-1050, Latvia, European Union. + * + * The interactive user interfaces in modified versions of the Program + * are required to display Appropriate Legal Notices in accordance with + * Section 5 of the GNU AGPL version 3. + * + * No trademark rights are granted under this License. + * + * All non-code elements of the Product, including illustrations, + * icon sets, and technical writing content, are licensed under the + * Creative Commons Attribution-ShareAlike 4.0 International License: + * https://creativecommons.org/licenses/by-sa/4.0/legalcode + * + * This license applies only to such non-code elements and does not + * modify or replace the licensing terms applicable to the Program's + * source code, which remains licensed under the GNU Affero General + * Public License v3. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + #ifndef SECURE_RANDOM_BYTES_H #define SECURE_RANDOM_BYTES_H From 60e773ced588c804acc3554f293e0990e7a19936 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Tue, 28 Apr 2026 18:17:32 +0300 Subject: [PATCH 10/12] refactor(pdf): use RandUInt for the CFF random operator Replace the local CryptoPP pool in FontOTWriter with RandUInt from OOXML/Base/Rand.h. Follow-up to fix(pdf): take the CFF random operator value from a CSPRNG Upstream-Subject: Fixes with rand (cherry picked from commit dfe6d300d871520b5af66ffa10a26810f159a73a) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- PdfFile/SrcWriter/FontOTWriter.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/PdfFile/SrcWriter/FontOTWriter.cpp b/PdfFile/SrcWriter/FontOTWriter.cpp index 1d668e01f6..8d14df7038 100644 --- a/PdfFile/SrcWriter/FontOTWriter.cpp +++ b/PdfFile/SrcWriter/FontOTWriter.cpp @@ -43,21 +43,10 @@ #include #include #include - -#include -#include "../../Common/3dParty/cryptopp/osrng.h" +#include "./../../OOXML/Base/Rand.h" namespace PdfWriter { - static unsigned int Rand1() - { - static CryptoPP::AutoSeededRandomPool prng; - static std::mutex prng_mutex; - unsigned int result; - std::lock_guard lock(prng_mutex); - prng.GenerateBlock(reinterpret_cast(&result), sizeof(result)); - return result; - } #define N_STD_STRINGS 391 static const char* scStandardStrings[N_STD_STRINGS] = { ".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft", @@ -3689,7 +3678,7 @@ namespace PdfWriter CharStringOperand newOperand; newOperand.IsInteger = false; - newOperand.RealValue = ((double)Rand1() + 1) / ((double)RAND_MAX + 1); + newOperand.RealValue = ((double)RandUInt() + 1) / ((double)RAND_MAX + 1); mOperandStack.push_back(newOperand); return inProgramCounter; From 9c2108ee16359da5bf0a15c7cb4fd879bbca51d2 Mon Sep 17 00:00:00 2001 From: "Oleg.Korshul" Date: Tue, 28 Apr 2026 18:53:14 +0300 Subject: [PATCH 11/12] build(mac): link the Security framework for Rand.h Link Security into StarMath2OOXML, PdfFile and x2t on mac and iOS for SecRandomCopyBytes, drop the CryptoPP link and define from StarMath2OOXML, and move the Rand.h include and the generators to the end of Unit.cpp. Follow-up to refactor(ooxml): use OS random sources instead of CryptoPP Upstream-Subject: Fix mac|ios build (cherry picked from commit 6a45740f98560bab82871c89928e8caf325976b2) Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 --- OOXML/Base/Unit.cpp | 53 ++++++++++--------- .../StarMath2OOXML/StarMath2OOXML.pro | 10 ++-- PdfFile/PdfFile.pro | 4 ++ X2tConverter/build/Qt/X2tConverter.pro | 4 ++ 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/OOXML/Base/Unit.cpp b/OOXML/Base/Unit.cpp index 0771574fe8..405a35f199 100644 --- a/OOXML/Base/Unit.cpp +++ b/OOXML/Base/Unit.cpp @@ -39,8 +39,6 @@ */ #include "Unit.h" #include -#include -#include "./Rand.h" double Cm_To_Mm (const double &dValue) { @@ -760,29 +758,6 @@ namespace XmlUtils return sstream.str(); } - int GenerateInt() - { - return static_cast(RandUInt()); - } - - std::wstring GenerateGuid() - { - std::wstring result; - - std::wstringstream sstream; - sstream << boost::wformat(L"%04X%04X-%04X-%04X-%04X-%04X%04X%04X") - % (RandUInt() & 0xffff) - % (RandUInt() & 0xffff) - % (RandUInt() & 0xffff) - % ((RandUInt() & 0x0fff) | 0x4000) - % ((RandUInt() & 0x3fff) | 0x8000) - % (RandUInt() & 0xffff) - % (RandUInt() & 0xffff) - % (RandUInt() & 0xffff); - result = sstream.str(); - - return result; - } std::wstring DoubleToString( double value, wchar_t* format ) { if ( format == nullptr ) return L""; @@ -1043,3 +1018,31 @@ namespace XmlUtils return buffer; } } + +#include "./Rand.h" +namespace XmlUtils +{ + int GenerateInt() + { + return static_cast(RandUInt()); + } + + std::wstring GenerateGuid() + { + std::wstring result; + + std::wstringstream sstream; + sstream << boost::wformat(L"%04X%04X-%04X-%04X-%04X-%04X%04X%04X") + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff) + % ((RandUInt() & 0x0fff) | 0x4000) + % ((RandUInt() & 0x3fff) | 0x8000) + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff) + % (RandUInt() & 0xffff); + result = sstream.str(); + + return result; + } +} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro index 1af216437b..046f36df92 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro @@ -43,14 +43,12 @@ CONFIG += plugin CORE_ROOT_DIR = $$PWD/../../../.. PWD_ROOT_DIR = $$PWD -DEFINES += STARMATH_USE_DYNAMIC_LIBRARY \ - CRYPTOPP_DISABLE_ASM +DEFINES += STARMATH_USE_DYNAMIC_LIBRARY include($$CORE_ROOT_DIR/Common/base.pri) include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri) include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri) -LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib ADD_DEPENDENCY(kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ @@ -68,3 +66,9 @@ HEADERS += \ $$PWD/typeConversion.h \ $$PWD/typeselements.h \ $$PWD/TFormulaSize.h + +core_mac | core_ios { + LIBS += -framework Security +} + + diff --git a/PdfFile/PdfFile.pro b/PdfFile/PdfFile.pro index 25ac45efa2..66c21f9995 100644 --- a/PdfFile/PdfFile.pro +++ b/PdfFile/PdfFile.pro @@ -245,3 +245,7 @@ SOURCES += PdfFile.cpp \ PdfReader.cpp \ PdfEditor.cpp \ OnlineOfficeBinToPdf.cpp + +core_mac | core_ios { + LIBS += -framework Security +} diff --git a/X2tConverter/build/Qt/X2tConverter.pro b/X2tConverter/build/Qt/X2tConverter.pro index 33f972acda..4094ba285f 100644 --- a/X2tConverter/build/Qt/X2tConverter.pro +++ b/X2tConverter/build/Qt/X2tConverter.pro @@ -79,3 +79,7 @@ include(X2tConverter.pri) HEADERS += ../../src/dylib/x2t.h SOURCES += ../../src/dylib/x2t.cpp } + +core_mac | core_ios { + LIBS += -framework Security +} From bb56c6d4a091925467f7ebed0bf56c15203cc3ad Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Fri, 4 Dec 2026 16:40:38 +0100 Subject: [PATCH 12/12] refactor(ooxml): drop the unused XmlUtils::Rand() declaration Unit.cpp no longer defines Rand() and nothing calls it. Unit.h gets our modification notice. Follow-up to refactor(ooxml): use OS random sources instead of CryptoPP Signed-off-by: Julius Knorr Assisted-by: ClaudeCode:claude-opus-5-5 No-test: removes an unused declaration, the CI build covers it --- OOXML/Base/Unit.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OOXML/Base/Unit.h b/OOXML/Base/Unit.h index a54936288e..bb9fc6d4e9 100644 --- a/OOXML/Base/Unit.h +++ b/OOXML/Base/Unit.h @@ -32,6 +32,11 @@ * * SPDX-License-Identifier: AGPL-3.0-only */ + +/* + * SPDX-FileCopyrightText: Euro-Office contributors + * Modified by Euro-Office contributors, see MODIFICATIONS.txt + */ #pragma once #include "Base.h" @@ -172,7 +177,6 @@ namespace XmlUtils std::wstring ToString(double value, const wchar_t* format); std::string ToString(double value, const char* format); - int Rand(); int GenerateInt(); std::wstring GenerateGuid();