Skip to content

Commit 014bf67

Browse files
authored
Fix PDFium abuse that leads to a crash on Windows ARM (#3460)
Signed-off-by: Jared Van Bortel <[email protected]>
1 parent 8c9f26e commit 014bf67

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Diff for: gpt4all-chat/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1010
- Fix "index N is not a prompt" when using LocalDocs with reasoning ([#3451](https://github.com/nomic-ai/gpt4all/pull/3451)
1111
- Work around rendering artifacts on Snapdragon SoCs with Windows ([#3450](https://github.com/nomic-ai/gpt4all/pull/3450))
1212
- Prevent DeepSeek-R1 reasoning from appearing in chat names and follow-up questions ([#3458](https://github.com/nomic-ai/gpt4all/pull/3458))
13+
- Fix LocalDocs crash on Windows ARM when reading PDFs ([#3460](https://github.com/nomic-ai/gpt4all/pull/3460))
1314

1415
## [3.8.0] - 2025-01-30
1516

Diff for: gpt4all-chat/deps/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ add_subdirectory(QXlsx/QXlsx)
1717

1818
if (NOT GPT4ALL_USING_QTPDF)
1919
# If we do not use QtPDF, we need to get PDFium.
20-
set(GPT4ALL_PDFIUM_TAG "chromium/6954")
20+
set(GPT4ALL_PDFIUM_TAG "chromium/6996")
2121
if (CMAKE_SYSTEM_NAME MATCHES Linux)
2222
FetchContent_Declare(
2323
pdfium
2424
URL "https://github.com/bblanchon/pdfium-binaries/releases/download/${GPT4ALL_PDFIUM_TAG}/pdfium-linux-x64.tgz"
25-
URL_HASH "SHA256=69917fd9543befc6c806254aff6c8a604d9e7cd3999a3e70fc32b8690d372da2"
25+
URL_HASH "SHA256=68b381b87efed539f2e33ae1e280304c9a42643a878cc296c1d66a93b0cb4335"
2626
)
2727
elseif (CMAKE_SYSTEM_NAME MATCHES Windows)
2828
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$")
2929
FetchContent_Declare(
3030
pdfium
3131
URL "https://github.com/bblanchon/pdfium-binaries/releases/download/${GPT4ALL_PDFIUM_TAG}/pdfium-win-x64.tgz"
32-
URL_HASH "SHA256=62ecac78fbaf658457beaffcc05eb147f493d435a2e1309e6a731808b4e80d38"
32+
URL_HASH "SHA256=83e714c302ceacccf403826d5cb57ea39b77f393d83b8d5781283012774a9378"
3333
)
3434
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|AARCH64|arm64|ARM64)$")
3535
FetchContent_Declare(
3636
pdfium
3737
URL "https://github.com/bblanchon/pdfium-binaries/releases/download/${GPT4ALL_PDFIUM_TAG}/pdfium-win-arm64.tgz"
38-
URL_HASH "SHA256=a0b69014467f2b9824776c064920bc95359c9ba0d88793bdda1894a0f22206f8"
38+
URL_HASH "SHA256=78e77e871453a4915cbf66fb381b951c9932f88a747c6b2b33c9f27ec2371445"
3939
)
4040
endif()
4141
elseif (CMAKE_SYSTEM_NAME MATCHES Darwin)
4242
FetchContent_Declare(
4343
pdfium
4444
URL "https://github.com/bblanchon/pdfium-binaries/releases/download/${GPT4ALL_PDFIUM_TAG}/pdfium-mac-univ.tgz"
45-
URL_HASH "SHA256=7442f1dc6bef90898b2b7bd38dbec369ddd81bbf66c1c5aac3a1b60e107098f9"
45+
URL_HASH "SHA256=e7577f3242ff9c1df50025f9615673a43601a201bc51ee4792975f98920793a2"
4646
)
4747
endif()
4848

Diff for: gpt4all-chat/src/database.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,6 @@ class PdfDocumentReader final : public DocumentReader {
12091209
FPDF_ClosePage(m_page);
12101210
if (m_doc)
12111211
FPDF_CloseDocument(m_doc);
1212-
FPDF_DestroyLibrary();
12131212
}
12141213

12151214
int page() const override { return m_currentPage; }
@@ -1224,7 +1223,7 @@ class PdfDocumentReader final : public DocumentReader {
12241223
return std::nullopt;
12251224

12261225
if (m_page)
1227-
FPDF_ClosePage(m_page);
1226+
FPDF_ClosePage(std::exchange(m_page, nullptr));
12281227
m_page = FPDF_LoadPage(m_doc, m_currentPage++);
12291228
if (!m_page)
12301229
throw std::runtime_error("Failed to load page.");

Diff for: gpt4all-chat/src/main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,9 @@ int main(int argc, char *argv[])
181181
// Otherwise, we can get a heap-use-after-free inside of llama.cpp.
182182
ChatListModel::globalInstance()->destroyChats();
183183

184+
#ifndef GPT4ALL_USE_QTPDF
185+
FPDF_DestroyLibrary();
186+
#endif
187+
184188
return res;
185189
}

0 commit comments

Comments
 (0)