Add stronger checks in span_util.h
The pdfium::internal::EnableIfLegalSpanConversion<T, U> guard should
ensure that sizeof(T) == sizeof(U), but we needn't rely on that if
we check size_bytes() instead of size().
Change-Id: Ic946747fb0f0442877dc9d7516efd10b1bd9c15b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/100430
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Auto-Submit: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/span_util.h b/core/fxcrt/span_util.h
index eace8c1..c911617 100644
--- a/core/fxcrt/span_util.h
+++ b/core/fxcrt/span_util.h
@@ -17,7 +17,7 @@
typename U,
typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
void spancpy(pdfium::span<T> dst, pdfium::span<U> src) {
- CHECK_GE(dst.size(), src.size());
+ CHECK_GE(dst.size_bytes(), src.size_bytes());
memcpy(dst.data(), src.data(), src.size_bytes());
}
@@ -26,7 +26,7 @@
typename U,
typename = pdfium::internal::EnableIfLegalSpanConversion<T, U>>
void spanmove(pdfium::span<T> dst, pdfium::span<U> src) {
- CHECK_GE(dst.size(), src.size());
+ CHECK_GE(dst.size_bytes(), src.size_bytes());
memmove(dst.data(), src.data(), src.size_bytes());
}