office-gobmx/external/pdfium/ubsan.patch
Stephan Bergmann a3351e6bf7 Avoid UBSan invalid-null-argument
...as seen at least with --without-latest-c++ after
d0b2f5f65e "pdfium: drop not needed annot.patch.1"
during CppunitTest_sw_core_text,

> workdir/UnpackedTarball/pdfium/core/fxcrt/string_data_template.cpp:76:20: runtime error: null pointer passed as argument 2, which is declared to never be null
> /usr/include/string.h:44:28: note: nonnull attribute specified here
>  #0 in fxcrt::StringDataTemplate<char>::CopyContents(char const*, unsigned long) at workdir/UnpackedTarball/pdfium/core/fxcrt/string_data_template.cpp:76:3
>  #1 in fxcrt::ByteString::ByteString(fxcrt::StringViewTemplate<char>, fxcrt::StringViewTemplate<char>) at workdir/UnpackedTarball/pdfium/core/fxcrt/bytestring.cpp:160:12
>  #2 in fxcrt::operator+(fxcrt::ByteString const&, fxcrt::ByteString const&) at workdir/UnpackedTarball/pdfium/core/fxcrt/bytestring.h:265:10
>  #3 in CPDFSDK_AppStream::SetAsTextField(absl::optional<fxcrt::WideString>) at workdir/UnpackedTarball/pdfium/fpdfsdk/cpdfsdk_appstream.cpp:1805:34
>  #4 in CPDFSDK_Widget::ResetAppearance(absl::optional<fxcrt::WideString>, CPDFSDK_Widget::ValueChanged) at workdir/UnpackedTarball/pdfium/fpdfsdk/cpdfsdk_widget.cpp:655:17
>  #5 in CPDFSDK_PageView::NewAnnot(CPDF_Annot*) at workdir/UnpackedTarball/pdfium/fpdfsdk/cpdfsdk_pageview.cpp:108:12
>  #6 in CPDFSDK_PageView::LoadFXAnnots() at workdir/UnpackedTarball/pdfium/fpdfsdk/cpdfsdk_pageview.cpp:566:45
>  #7 in CPDFSDK_FormFillEnvironment::GetOrCreatePageView(IPDF_Page*) at workdir/UnpackedTarball/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp:625:14
>  #8 in (anonymous namespace)::FormHandleToPageView(fpdf_form_handle_t__*, fpdf_page_t__*) at workdir/UnpackedTarball/pdfium/fpdfsdk/fpdf_formfill.cpp:169:39
>  #9 in FORM_OnAfterLoadPage at workdir/UnpackedTarball/pdfium/fpdfsdk/fpdf_formfill.cpp:730:37
>  #10 in vcl::pdf::(anonymous namespace)::PDFiumPageImpl::onAfterLoadPage(vcl::pdf::PDFiumDocument*) at vcl/source/pdf/PDFiumLibrary.cxx:764:5
>  #11 in testContentControlPDFFont::TestBody() at sw/qa/core/text/text.cxx:746:12

Change-Id: Iba73a9401eb10a8c03843dba038cd3a6eeeb0c4a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141210
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-10-11 15:25:31 +02:00

33 lines
1.2 KiB
Diff

--- core/fxcrt/string_data_template.cpp
+++ core/fxcrt/string_data_template.cpp
@@ -73,7 +73,7 @@
size_t nLen) {
DCHECK_GE(nLen, 0);
DCHECK_LE(nLen, m_nAllocLength);
- memcpy(m_String, pStr, nLen * sizeof(CharType));
+ if (nLen != 0) memcpy(m_String, pStr, nLen * sizeof(CharType));
m_String[nLen] = 0;
}
@@ -82,7 +82,8 @@ void StringDataTemplate<CharType>::CopyContentsAt(size_t offset,
DCHECK_GE(offset, 0);
DCHECK_GE(nLen, 0);
DCHECK_LE(offset + nLen, m_nAllocLength);
- memcpy(m_String + offset, pStr, nLen * sizeof(CharType));
+ if (nLen != 0)
+ memcpy(m_String + offset, pStr, nLen * sizeof(CharType));
m_String[offset + nLen] = 0;
}
--- core/fxge/cfx_glyphcache.cpp
+++ core/fxge/cfx_glyphcache.cpp
@@ -183,7 +183,8 @@ std::unique_ptr<CFX_GlyphBitmap> CFX_GlyphCache::RenderGlyph(
}
}
} else {
- memset(pDestBuf, 0, dest_pitch * bmheight);
+ if (dest_pitch != 0 && bmheight != 0)
+ memset(pDestBuf, 0, dest_pitch * bmheight);
int rowbytes = std::min(abs(src_pitch), dest_pitch);
for (int row = 0; row < bmheight; row++)
memcpy(pDestBuf + row * dest_pitch, pSrcBuf + row * src_pitch, rowbytes);