external/pdfium/UnpackedTarball_pdfium.mk                       |    3 
 external/pdfium/retrieve-MIME-type-from-PDF-attachments.patch.1 |   89 
++++++++++
 2 files changed, 92 insertions(+)

New commits:
commit 117207b42185637f5ac56c61a7ff8eae681049d3
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed May 21 09:15:10 2025 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed May 21 10:36:04 2025 +0200

    pdfium: backport FPDFAttachment_GetSubtype() API
    
    Upstream uses so much C++20 by now that updating pdfium is hard till we
    use clang-cl from VS2019.
    
    This is a fix for <https://issues.chromium.org/issues/408241034>, which
    is something David is waiting for.
    
    Change-Id: I74ec98081adb65a6d534874453f92ca90ac232f6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185587
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/external/pdfium/UnpackedTarball_pdfium.mk 
b/external/pdfium/UnpackedTarball_pdfium.mk
index 305246bce888..bf93dcd2e09a 100644
--- a/external/pdfium/UnpackedTarball_pdfium.mk
+++ b/external/pdfium/UnpackedTarball_pdfium.mk
@@ -16,6 +16,9 @@ pdfium_patches += constexpr-template.patch
 
 pdfium_patches += system-abseil.diff
 
+# https://pdfium-review.googlesource.com/c/pdfium/+/130970
+pdfium_patches += retrieve-MIME-type-from-PDF-attachments.patch.1
+
 ifeq ($(OS),WNT)
 pdfium_patches += pdfium-vs2019-arm64_no-__umulh.patch.1
 endif
diff --git a/external/pdfium/retrieve-MIME-type-from-PDF-attachments.patch.1 
b/external/pdfium/retrieve-MIME-type-from-PDF-attachments.patch.1
new file mode 100644
index 000000000000..66a99cf1cd1f
--- /dev/null
+++ b/external/pdfium/retrieve-MIME-type-from-PDF-attachments.patch.1
@@ -0,0 +1,89 @@
+From 87a497287e02ba8cfa61418c2443e205d5b7e054 Mon Sep 17 00:00:00 2001
+From: Helmut Januschka <hel...@januschka.com>
+Date: Mon, 28 Apr 2025 16:48:20 -0700
+Subject: [PATCH] Add API to retrieve MIME type from PDF attachments
+
+Adds new API to retrieve values from the embedded file stream
+dictionary of PDF attachments:
+
+FPDFAttachment_GetSubtype() - Specifically retrieves the MIME type
+
+Bug: 408241034
+Change-Id: Ia42813d0423dbdad3105f9ac1c8da4f3976e92c9
+Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/130970
+Commit-Queue: Lei Zhang <thes...@chromium.org>
+Reviewed-by: Tom Sepez <tse...@chromium.org>
+Reviewed-by: Lei Zhang <thes...@chromium.org>
+---
+ fpdfsdk/fpdf_attachment.cpp              | 27 ++++++++++++++++++
+ fpdfsdk/fpdf_attachment_embeddertest.cpp | 36 ++++++++++++++++++++++++
+ fpdfsdk/fpdf_view_c_api_test.c           |  1 +
+ public/fpdf_attachment.h                 | 17 +++++++++++
+ 4 files changed, 81 insertions(+)
+
+diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp
+index c5f251538..eaba2a78f 100644
+--- a/fpdfsdk/fpdf_attachment.cpp
++++ b/fpdfsdk/fpdf_attachment.cpp
+@@ -304,3 +304,30 @@ FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment,
+                                        static_cast<size_t>(buflen))));
+   return true;
+ }
++
++FPDF_EXPORT unsigned long FPDF_CALLCONV
++FPDFAttachment_GetSubtype(FPDF_ATTACHMENT attachment,
++                          FPDF_WCHAR* buffer,
++                          unsigned long buflen) {
++  CPDF_Object* file = CPDFObjectFromFPDFAttachment(attachment);
++  if (!file) {
++    return 0;
++  }
++
++  // SAFETY: required from caller.
++  auto buffer_span = UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, buflen));
++  CPDF_FileSpec spec(pdfium::WrapRetain(file));
++  RetainPtr<const CPDF_Stream> file_stream = spec.GetFileStream();
++  if (!file_stream) {
++    return Utf16EncodeMaybeCopyAndReturnLength(WideString(), buffer_span);
++  }
++
++  ByteString subtype = file_stream->GetDict()->GetNameFor("Subtype");
++  if (subtype.IsEmpty()) {
++    // Per API description, return an empty string in these cases.
++    return Utf16EncodeMaybeCopyAndReturnLength(WideString(), buffer_span);
++  }
++
++  return Utf16EncodeMaybeCopyAndReturnLength(
++      PDF_DecodeText(subtype.unsigned_span()), buffer_span);
++}
+diff --git a/public/fpdf_attachment.h b/public/fpdf_attachment.h
+index d25bddab6..a8a40b34b 100644
+--- a/public/fpdf_attachment.h
++++ b/public/fpdf_attachment.h
+@@ -172,6 +172,23 @@ FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment,
+                        unsigned long buflen,
+                        unsigned long* out_buflen);
+ 
++// Experimental API.
++// Get the MIME type (Subtype) of the embedded file |attachment|. |buffer| is
++// only modified if |buflen| is longer than the length of the MIME type 
string.
++// If the Subtype is not found or if there is no file stream, an empty string
++// would be copied to |buffer| and the return value would be 2. On other 
errors,
++// nothing would be added to |buffer| and the return value would be 0.
++//
++//   attachment - handle to an attachment.
++//   buffer     - buffer for holding the MIME type string encoded in UTF-16LE.
++//   buflen     - length of the buffer in bytes.
++//
++// Returns the length of the MIME type string in bytes.
++FPDF_EXPORT unsigned long FPDF_CALLCONV
++FPDFAttachment_GetSubtype(FPDF_ATTACHMENT attachment,
++                          FPDF_WCHAR* buffer,
++                          unsigned long buflen);
++
+ #ifdef __cplusplus
+ }  // extern "C"
+ #endif  // __cplusplus
+-- 
+2.43.0
+

Reply via email to