Use static subspan<>() methods when we have a static span argument.
Or are likely to have a static span argument in the future when
creating a span from a fixed-size container. These will someday
be more efficient once we can pull in Chromiums base:: span.
Change-Id: I79f638a6fc0a5839bdcb73580cdfad3fae5b1e16
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121215
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
diff --git a/core/fdrm/fx_crypt.cpp b/core/fdrm/fx_crypt.cpp
index 0320144..e38000f 100644
--- a/core/fdrm/fx_crypt.cpp
+++ b/core/fdrm/fx_crypt.cpp
@@ -20,23 +20,24 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void md5_process(CRYPT_md5_context* ctx, pdfium::span<const uint8_t, 64> data) {
- uint32_t X[16];
- X[0] = fxcrt::GetUInt32LSBFirst(data.subspan(0, 4));
- X[1] = fxcrt::GetUInt32LSBFirst(data.subspan(4, 4));
- X[2] = fxcrt::GetUInt32LSBFirst(data.subspan(8, 4));
- X[3] = fxcrt::GetUInt32LSBFirst(data.subspan(12, 4));
- X[4] = fxcrt::GetUInt32LSBFirst(data.subspan(16, 4));
- X[5] = fxcrt::GetUInt32LSBFirst(data.subspan(20, 4));
- X[6] = fxcrt::GetUInt32LSBFirst(data.subspan(24, 4));
- X[7] = fxcrt::GetUInt32LSBFirst(data.subspan(28, 4));
- X[8] = fxcrt::GetUInt32LSBFirst(data.subspan(32, 4));
- X[9] = fxcrt::GetUInt32LSBFirst(data.subspan(36, 4));
- X[10] = fxcrt::GetUInt32LSBFirst(data.subspan(40, 4));
- X[11] = fxcrt::GetUInt32LSBFirst(data.subspan(44, 4));
- X[12] = fxcrt::GetUInt32LSBFirst(data.subspan(48, 4));
- X[13] = fxcrt::GetUInt32LSBFirst(data.subspan(52, 4));
- X[14] = fxcrt::GetUInt32LSBFirst(data.subspan(56, 4));
- X[15] = fxcrt::GetUInt32LSBFirst(data.subspan(60, 4));
+ uint32_t X[16] = {
+ fxcrt::GetUInt32LSBFirst(data.subspan<0, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<4, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<8, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<12, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<16, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<20, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<24, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<28, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<32, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<36, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<40, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<44, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<48, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<52, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<56, 4>()),
+ fxcrt::GetUInt32LSBFirst(data.subspan<60, 4>()),
+ };
uint32_t A = ctx->state[0];
uint32_t B = ctx->state[1];
uint32_t C = ctx->state[2];
@@ -203,16 +204,16 @@
pdfium::span<uint8_t, 16> digest) {
uint8_t msglen[8];
auto msglen_span = pdfium::make_span(msglen);
- fxcrt::PutUInt32LSBFirst(context->total[0], msglen_span.subspan(0, 4));
- fxcrt::PutUInt32LSBFirst(context->total[1], msglen_span.subspan(4, 4));
+ fxcrt::PutUInt32LSBFirst(context->total[0], msglen_span.subspan<0, 4>());
+ fxcrt::PutUInt32LSBFirst(context->total[1], msglen_span.subspan<4, 4>());
uint32_t last = (context->total[0] >> 3) & 0x3F;
uint32_t padn = (last < 56) ? (56 - last) : (120 - last);
CRYPT_MD5Update(context, pdfium::make_span(md5_padding).first(padn));
CRYPT_MD5Update(context, msglen);
- fxcrt::PutUInt32LSBFirst(context->state[0], digest.subspan(0, 4));
- fxcrt::PutUInt32LSBFirst(context->state[1], digest.subspan(4, 4));
- fxcrt::PutUInt32LSBFirst(context->state[2], digest.subspan(8, 4));
- fxcrt::PutUInt32LSBFirst(context->state[3], digest.subspan(12, 4));
+ fxcrt::PutUInt32LSBFirst(context->state[0], digest.subspan<0, 4>());
+ fxcrt::PutUInt32LSBFirst(context->state[1], digest.subspan<4, 4>());
+ fxcrt::PutUInt32LSBFirst(context->state[2], digest.subspan<8, 4>());
+ fxcrt::PutUInt32LSBFirst(context->state[3], digest.subspan<12, 4>());
}
void CRYPT_MD5Generate(pdfium::span<const uint8_t> data,
diff --git a/core/fdrm/fx_crypt_aes.cpp b/core/fdrm/fx_crypt_aes.cpp
index a191107..48a1c2f 100644
--- a/core/fdrm/fx_crypt_aes.cpp
+++ b/core/fdrm/fx_crypt_aes.cpp
@@ -625,7 +625,7 @@
pdfium::span<uint8_t> dest,
pdfium::span<const uint8_t> src) {
CHECK_EQ((src.size() & 15), 0);
- auto ctx_iv = pdfium::make_span(ctx->iv).first(4u);
+ auto ctx_iv = pdfium::make_span(ctx->iv).first<4u>();
while (!src.empty()) {
for (auto& iv_element : ctx_iv) {
iv_element ^= fxcrt::GetUInt32MSBFirst(src.first(4u));
diff --git a/core/fdrm/fx_crypt_sha.cpp b/core/fdrm/fx_crypt_sha.cpp
index 3b47e03..082314e 100644
--- a/core/fdrm/fx_crypt_sha.cpp
+++ b/core/fdrm/fx_crypt_sha.cpp
@@ -418,7 +418,7 @@
c[5] = (total_bits >> 16) & 0xFF;
c[6] = (total_bits >> 8) & 0xFF;
c[7] = (total_bits >> 0) & 0xFF;
- CRYPT_SHA1Update(context, pdfium::make_span(c).first(8u));
+ CRYPT_SHA1Update(context, pdfium::make_span(c).first<8u>());
for (int i = 0; i < 5; i++) {
digest[i * 4] = (context->h[i] >> 24) & 0xFF;
digest[i * 4 + 1] = (context->h[i] >> 16) & 0xFF;
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index 92ead13..0f6afc9 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -573,7 +573,7 @@
static constexpr char kStemChars[] = {'i', 'I', '!', '1'};
static constexpr pdfium::span<const char> kStemSpan{kStemChars};
uint32_t glyph = pEncoding->GlyphFromCharCode(kStemSpan.front());
- const auto remaining = kStemSpan.subspan(1);
+ const auto remaining = kStemSpan.subspan<1>();
nStemV = pFont->GetGlyphWidth(glyph);
for (auto ch : remaining) {
glyph = pEncoding->GlyphFromCharCode(ch);
diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp
index 51208d1..89ce587 100644
--- a/core/fpdfapi/page/cpdf_meshstream.cpp
+++ b/core/fpdfapi/page/cpdf_meshstream.cpp
@@ -215,7 +215,7 @@
float result[kMaxComponents] = {};
for (const auto& func : m_funcs) {
if (func && func->OutputCount() <= kMaxComponents) {
- func->Call(pdfium::make_span(color_value).first(1u), result);
+ func->Call(pdfium::make_span(color_value).first<1u>(), result);
}
}
return m_pCS->GetRGBOrZerosOnError(result);
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index 4ecff9c..b8621df 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -594,7 +594,8 @@
CRYPT_MD5Update(&md5, file_id.unsigned_span());
uint8_t digest[32];
- auto partial_digest_span = pdfium::make_span(digest).first(16u);
+ auto partial_digest_span = pdfium::make_span(digest).first<16u>();
+ auto remaining_digest_span = pdfium::make_span(digest).subspan<16u>();
CRYPT_MD5Finish(&md5, partial_digest_span);
CRYPT_ArcFourCryptBlock(partial_digest_span,
pdfium::make_span(m_EncryptKey).first(key_len));
@@ -606,8 +607,7 @@
CRYPT_ArcFourCryptBlock(partial_digest_span,
pdfium::make_span(tempkey).first(key_len));
}
- CRYPT_MD5Generate(pdfium::make_span(digest).first(16u),
- pdfium::make_span(digest).subspan(16u));
+ CRYPT_MD5Generate(partial_digest_span, remaining_digest_span);
pEncryptDict->SetNewFor<CPDF_String>("U",
UNSAFE_TODO(ByteString(digest, 32)));
}
@@ -634,8 +634,8 @@
} else {
CRYPT_SHA256Start(&sha2);
CRYPT_SHA256Update(&sha2, password.unsigned_span());
- CRYPT_SHA256Update(&sha2, pdfium::make_span(digest).first(8u));
- CRYPT_SHA256Finish(&sha2, pdfium::make_span(digest1).first(32u));
+ CRYPT_SHA256Update(&sha2, pdfium::make_span(digest).first<8u>());
+ CRYPT_SHA256Finish(&sha2, pdfium::make_span(digest1).first<32u>());
}
UNSAFE_TODO(FXSYS_memcpy(digest1 + 32, digest, 16));
pEncryptDict->SetNewFor<CPDF_String>("U",
@@ -645,8 +645,8 @@
} else {
CRYPT_SHA256Start(&sha2);
CRYPT_SHA256Update(&sha2, password.unsigned_span());
- CRYPT_SHA256Update(&sha2, pdfium::make_span(digest).subspan(8, 8));
- CRYPT_SHA256Finish(&sha2, pdfium::make_span(digest1).first(32));
+ CRYPT_SHA256Update(&sha2, pdfium::make_span(digest).subspan<8, 8>());
+ CRYPT_SHA256Finish(&sha2, pdfium::make_span(digest1).first<32>());
}
CRYPT_aes_context aes = {};
CRYPT_AESSetKey(&aes, digest1, 32);
@@ -677,7 +677,7 @@
uint32_t random_value;
FX_Random_GenerateMT(pdfium::span_from_ref(random_value));
fxcrt::Copy(pdfium::byte_span_from_ref(random_value),
- pdfium::make_span(buf).subspan(12, 4));
+ pdfium::make_span(buf).subspan<12, 4>());
CRYPT_aes_context aes = {};
CRYPT_AESSetKey(&aes, m_EncryptKey.data(), m_EncryptKey.size());
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index b223ad5..56e9973 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -101,7 +101,7 @@
Seek(From::Begin, 0);
uint32_t bom = 0;
- ReadData(pdfium::byte_span_from_ref(bom).first(3));
+ ReadData(pdfium::byte_span_from_ref(bom).first<3>());
bom &= BOM_UTF8_MASK;
if (bom == BOM_UTF8) {
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index 80896a7..04f2d1d 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -194,14 +194,14 @@
return;
}
uint32_t magic =
- fxcrt::GetUInt32MSBFirst(pdfium::make_span(buffer).first(4u));
+ fxcrt::GetUInt32MSBFirst(pdfium::make_span(buffer).first<4u>());
if (magic != kTableTTCF) {
ReportFace(path, pFile.get(), filesize, 0);
return;
}
uint32_t nFaces =
- fxcrt::GetUInt32MSBFirst(pdfium::make_span(buffer).subspan(8));
+ fxcrt::GetUInt32MSBFirst(pdfium::make_span(buffer).subspan<8u>());
FX_SAFE_SIZE_T safe_face_bytes = nFaces;
safe_face_bytes *= 4;
if (!safe_face_bytes.IsValid())
@@ -231,7 +231,7 @@
return;
uint32_t nTables =
- fxcrt::GetUInt16MSBFirst(pdfium::as_byte_span(buffer).subspan(4));
+ fxcrt::GetUInt16MSBFirst(pdfium::as_byte_span(buffer).subspan<4, 2>());
ByteString tables = ReadStringFromFile(pFile, nTables * 16);
if (tables.IsEmpty())
return;