Use more FXSYS_*_GET_MSBFIRST macros
Avoids possible UB issues when uint8_t with high bit set gets
widened to int, then shifted by 24.
Change-Id: I84c757e214247d46ea35e39c4d52842bc23e967c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82977
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cfx_cttgsubtable.cpp b/core/fpdfapi/font/cfx_cttgsubtable.cpp
index bad7f71..f79484f 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.cpp
+++ b/core/fpdfapi/font/cfx_cttgsubtable.cpp
@@ -147,25 +147,25 @@
}
int16_t CFX_CTTGSUBTable::GetInt16(FT_Bytes& p) const {
- uint16_t ret = p[0] << 8 | p[1];
+ uint16_t ret = FXSYS_UINT16_GET_MSBFIRST(p);
p += 2;
return *(int16_t*)&ret;
}
uint16_t CFX_CTTGSUBTable::GetUInt16(FT_Bytes& p) const {
- uint16_t ret = p[0] << 8 | p[1];
+ uint16_t ret = FXSYS_UINT16_GET_MSBFIRST(p);
p += 2;
return ret;
}
int32_t CFX_CTTGSUBTable::GetInt32(FT_Bytes& p) const {
- uint32_t ret = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+ uint32_t ret = FXSYS_UINT32_GET_MSBFIRST(p);
p += 4;
return *(int32_t*)&ret;
}
uint32_t CFX_CTTGSUBTable::GetUInt32(FT_Bytes& p) const {
- uint32_t ret = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+ uint32_t ret = FXSYS_UINT32_GET_MSBFIRST(p);
p += 4;
return ret;
}
diff --git a/core/fxcodec/basic/basicmodule.cpp b/core/fxcodec/basic/basicmodule.cpp
index 6cb8eb3..13678ff 100644
--- a/core/fxcodec/basic/basicmodule.cpp
+++ b/core/fxcodec/basic/basicmodule.cpp
@@ -330,10 +330,8 @@
uint32_t pos = 0;
uint32_t line_length = 0;
while (src_span.size() >= 4 && pos < src_span.size() - 3) {
- uint32_t val = ((uint32_t)(src_span[pos]) << 24) +
- ((uint32_t)(src_span[pos + 1]) << 16) +
- ((uint32_t)(src_span[pos + 2]) << 8) +
- (uint32_t)(src_span[pos + 3]);
+ auto val_span = src_span.subspan(pos, 4);
+ uint32_t val = FXSYS_UINT32_GET_MSBFIRST(val_span);
pos += 4;
if (val == 0) { // All zero special case
*out = 'z';
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index d30ae44..91c2e99 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -15,6 +15,7 @@
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_font.h"
#include "core/fxge/cfx_fontmapper.h"
#include "core/fxge/cfx_fontmgr.h"
@@ -337,7 +338,7 @@
}
inline uint16_t GetUInt16(const uint8_t* p) {
- return static_cast<uint16_t>(p[0] << 8 | p[1]);
+ return FXSYS_UINT16_GET_MSBFIRST(p);
}
extern "C" {