Fix some unsafe usage in cpdfdsk_{helpers,interactiveform}.cpp
Change-Id: I936f9a9d750eda57c0c8c87a1d3531607bd26d90
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/118075
Reviewed-by: Thomas Sepez <tsepez@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index b97aca7..d2288c1 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -72,14 +72,18 @@
return pdfium::checked_cast<unsigned long>(stream_data_span.size());
}
+// TODO(tsepez): should be UNSAFE_BUFFER_USAGE.
size_t FPDFWideStringLength(const unsigned short* str) {
if (!str) {
return 0;
}
size_t len = 0;
- while (str[len]) {
- len++;
- }
+ // SAFETY: NUL-termination required from caller.
+ UNSAFE_BUFFERS({
+ while (str[len]) {
+ len++;
+ }
+ });
return len;
}
diff --git a/fpdfsdk/cpdfsdk_interactiveform.h b/fpdfsdk/cpdfsdk_interactiveform.h
index d2f54e1..5b3c7ab 100644
--- a/fpdfsdk/cpdfsdk_interactiveform.h
+++ b/fpdfsdk/cpdfsdk_interactiveform.h
@@ -7,6 +7,7 @@
#ifndef FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_
#define FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_
+#include <array>
#include <functional>
#include <map>
#include <memory>
@@ -115,8 +116,8 @@
bool m_bCalculate = true;
bool m_bBusy = false;
uint8_t m_HighlightAlpha = 0;
- FX_COLORREF m_HighlightColor[kFormFieldTypeCount];
- bool m_NeedsHighlight[kFormFieldTypeCount];
+ std::array<FX_COLORREF, kFormFieldTypeCount> m_HighlightColor;
+ std::array<bool, kFormFieldTypeCount> m_NeedsHighlight;
};
#endif // FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_