Skip to content

Commit 62739f9

Browse files
committed
Add RedHat patches for big-endian CPUs
manually updated cfx_seekablestreamproxy.cpp to newer pdfium version tested that patches apply and build on little endian
1 parent 2d53122 commit 62739f9

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

REUSE.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ SPDX-FileCopyrightText = [
143143
]
144144
SPDX-License-Identifier = "BSD-3-Clause OR Apache-2.0"
145145

146+
[[annotations]]
147+
path = [
148+
"pdfium_patches/bigendian.patch",
149+
"pdfium_patches/bigendian_test.patch",
150+
]
151+
precedence = "aggregate"
152+
SPDX-FileCopyrightText = [
153+
"2025 Christian Heimes <[email protected]>",
154+
"2025 geisserml <[email protected]>",
155+
]
156+
SPDX-License-Identifier = "LicenseRef-Ignore"
157+
SPDX-FileComment = '''
158+
Derived from RedHat packaging repository: https://github.com/tiran/libpdfium/blob/d99370b3ac7f0c9cd7222be2dfab2c7b648f2e9e/0001-bigendian.patch
159+
Repo does not have an own license file, but assumably the patches are being made available under pdfium's license, or leastways an open-source license.
160+
'''
161+
146162
[[annotations]]
147163
path = [
148164
"docs/build/.gitkeep",

pdfium_patches/bigendian.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
2+
index 33cc528..5fa42bf 100644
3+
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
4+
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
5+
@@ -89,11 +89,19 @@ void SwapByteOrder(pdfium::span<uint16_t> str) {
6+
7+
} // namespace
8+
9+
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
10+
#define BOM_UTF8_MASK 0x00FFFFFF
11+
#define BOM_UTF8 0x00BFBBEF
12+
#define BOM_UTF16_MASK 0x0000FFFF
13+
#define BOM_UTF16_BE 0x0000FFFE
14+
#define BOM_UTF16_LE 0x0000FEFF
15+
+#else
16+
+#define BOM_UTF8_MASK 0xFFFFFF00
17+
+#define BOM_UTF8 0xEFBBBF00
18+
+#define BOM_UTF16_MASK 0xFFFF0000
19+
+#define BOM_UTF16_BE 0xFEFF0000
20+
+#define BOM_UTF16_LE 0xFFFE0000
21+
+#endif
22+
23+
CFX_SeekableStreamProxy::CFX_SeekableStreamProxy(
24+
const RetainPtr<IFX_SeekableReadStream>& stream)
25+
@@ -188,9 +196,15 @@ size_t CFX_SeekableStreamProxy::ReadBlock(pdfium::span<wchar_t> buffer) {
26+
size_t bytes_read =
27+
ReadData(pdfium::as_writable_bytes(buffer).first(bytes_to_read));
28+
size_t elements = bytes_read / sizeof(uint16_t);
29+
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
30+
if (code_page_ == FX_CodePage::kUTF16BE) {
31+
SwapByteOrder(fxcrt::reinterpret_span<uint16_t>(buffer).first(elements));
32+
}
33+
+#else
34+
+ if (m_wCodePage == FX_CodePage::kUTF16LE) {
35+
+ SwapByteOrder(fxcrt::reinterpret_span<uint16_t>(buffer).first(elements));
36+
+ }
37+
+#endif
38+
UTF16ToWChar(buffer.first(elements));
39+
return elements;
40+
}

pdfium_patches/bigendian_test.patch

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--- a/core/fxcrt/binary_buffer_unittest.cpp
2+
+++ b/core/fxcrt/binary_buffer_unittest.cpp
3+
@@ -3,6 +3,7 @@
4+
// found in the LICENSE file.
5+
6+
#include "core/fxcrt/binary_buffer.h"
7+
+#include "core/fxcrt/byteorder.h"
8+
9+
#include <utility>
10+
#include <vector>
11+
@@ -122,7 +123,7 @@
12+
// Assumes little endian.
13+
TEST(BinaryBuffer, AppendUint16) {
14+
BinaryBuffer buffer;
15+
- buffer.AppendUint16(0x4321);
16+
+ buffer.AppendUint16(FromLE16(0x4321));
17+
EXPECT_EQ(2u, buffer.GetSize());
18+
EXPECT_EQ(2u, buffer.GetLength());
19+
EXPECT_EQ(0x21u, buffer.GetSpan()[0]);
20+
@@ -132,7 +133,7 @@
21+
// Assumes little endian.
22+
TEST(BinaryBuffer, AppendUint32) {
23+
BinaryBuffer buffer;
24+
- buffer.AppendUint32(0x87654321);
25+
+ buffer.AppendUint32(FromLE32(0x87654321));
26+
EXPECT_EQ(4u, buffer.GetSize());
27+
EXPECT_EQ(4u, buffer.GetLength());
28+
EXPECT_EQ(0x21u, buffer.GetSpan()[0]);
29+

setupsrc/pypdfium2_setup/build_native.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ def get_sources(deps_info, short_ver, with_tests, compiler, clang_path, single_l
188188
"#if 1 // defined(COMPONENT_BUILD)",
189189
is_regex=False, exp_count=1,
190190
)
191+
if sys.byteorder == "big":
192+
git_apply_patch(PatchDir/"bigendian.patch", cwd=PDFIUM_DIR)
193+
if with_tests:
194+
git_apply_patch(PatchDir/"bigendian_test.patch", cwd=PDFIUM_DIR)
191195

192196
do_patches = _fetch_dep(deps_info, "build", PDFIUM_DIR/"build", reset=reset)
193197
if do_patches:

0 commit comments

Comments
 (0)