From cfd4d57800835011b028435e064f13c29243d6e6 Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 8 Apr 2016 14:38:54 -0700 Subject: Make converstion explicit from CFX_ByteString to uint8_t* BUG= Review URL: https://codereview.chromium.org/1868293002 --- core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 2 +- core/fpdfapi/fpdf_page/cpdf_colorspace.cpp | 2 +- .../fpdf_parser/cpdf_standard_security_handler.cpp | 42 +++++++++++----------- core/fxcrt/include/fx_string.h | 8 +---- core/fxge/ge/fx_ge_fontmap.cpp | 17 ++++----- fpdfsdk/fpdf_flatten.cpp | 12 +++---- xfa/fxfa/app/xfa_ffimageedit.cpp | 2 +- xfa/fxfa/app/xfa_ffwidget.cpp | 2 +- 8 files changed, 39 insertions(+), 48 deletions(-) diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index c0d2ab0dd3..a337cf59ff 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -2011,7 +2011,7 @@ void CPDF_Creator::InitID(FX_BOOL bDefault) { CPDF_StandardSecurityHandler handler; CFX_ByteString user_pass = m_pParser->GetPassword(); uint32_t flag = PDF_ENCRYPT_CONTENT; - handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, + handler.OnCreate(m_pEncryptDict, m_pIDArray, user_pass.raw_str(), user_pass.GetLength(), flag); if (m_bNewCrypto) { delete m_pCryptoHandler; diff --git a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp index b5dcd46235..79faebafc9 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp @@ -1029,7 +1029,7 @@ FX_BOOL CPDF_IndexedCS::GetRGB(FX_FLOAT* pBuf, } CFX_FixedBufGrow Comps(m_nBaseComponents); FX_FLOAT* comps = Comps; - const uint8_t* pTable = m_Table; + const uint8_t* pTable = m_Table.raw_str(); for (int i = 0; i < m_nBaseComponents; i++) { comps[i] = m_pCompMinMax[i * 2] + diff --git a/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp b/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp index b7ed0315bb..627ff5263f 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp @@ -98,18 +98,18 @@ FX_BOOL CPDF_StandardSecurityHandler::OnInit(CPDF_Parser* pParser, } FX_BOOL CPDF_StandardSecurityHandler::CheckSecurity(int32_t key_len) { CFX_ByteString password = m_pParser->GetPassword(); - if (CheckPassword(password, password.GetLength(), TRUE, m_EncryptKey, - key_len)) { + if (CheckPassword(password.raw_str(), password.GetLength(), TRUE, + m_EncryptKey, key_len)) { if (password.IsEmpty()) { - if (!CheckPassword(password, password.GetLength(), FALSE, m_EncryptKey, - key_len)) { + if (!CheckPassword(password.raw_str(), password.GetLength(), FALSE, + m_EncryptKey, key_len)) { return FALSE; } } return TRUE; } - return CheckPassword(password, password.GetLength(), FALSE, m_EncryptKey, - key_len); + return CheckPassword(password.raw_str(), password.GetLength(), FALSE, + m_EncryptKey, key_len); } uint32_t CPDF_StandardSecurityHandler::GetPermissions() { return m_Permissions; @@ -320,18 +320,18 @@ FX_BOOL CPDF_StandardSecurityHandler::AES256_CheckPassword( if (ukey.GetLength() < 48) { return FALSE; } - const uint8_t* pkey = bOwner ? (const uint8_t*)okey : (const uint8_t*)ukey; + const uint8_t* pkey = (bOwner ? okey : ukey).raw_str(); uint8_t sha[128]; uint8_t digest[32]; if (m_Revision >= 6) { Revision6_Hash(password, size, (const uint8_t*)pkey + 32, - (bOwner ? (const uint8_t*)ukey : NULL), digest); + bOwner ? ukey.raw_str() : nullptr, digest); } else { CRYPT_SHA256Start(sha); CRYPT_SHA256Update(sha, password, size); CRYPT_SHA256Update(sha, pkey + 32, 8); if (bOwner) { - CRYPT_SHA256Update(sha, ukey, 48); + CRYPT_SHA256Update(sha, ukey.raw_str(), 48); } CRYPT_SHA256Finish(sha, digest); } @@ -343,13 +343,13 @@ FX_BOOL CPDF_StandardSecurityHandler::AES256_CheckPassword( } if (m_Revision >= 6) { Revision6_Hash(password, size, (const uint8_t*)pkey + 40, - (bOwner ? (const uint8_t*)ukey : NULL), digest); + bOwner ? ukey.raw_str() : nullptr, digest); } else { CRYPT_SHA256Start(sha); CRYPT_SHA256Update(sha, password, size); CRYPT_SHA256Update(sha, pkey + 40, 8); if (bOwner) { - CRYPT_SHA256Update(sha, ukey, 48); + CRYPT_SHA256Update(sha, ukey.raw_str(), 48); } CRYPT_SHA256Finish(sha, digest); } @@ -364,7 +364,7 @@ FX_BOOL CPDF_StandardSecurityHandler::AES256_CheckPassword( uint8_t iv[16]; FXSYS_memset(iv, 0, 16); CRYPT_AESSetIV(aes, iv); - CRYPT_AESDecrypt(aes, key, ekey, 32); + CRYPT_AESDecrypt(aes, key, ekey.raw_str(), 32); CRYPT_AESSetKey(aes, 16, key, 32, FALSE); CRYPT_AESSetIV(aes, iv); CFX_ByteString perms = m_pEncryptDict->GetStringBy("Perms"); @@ -377,7 +377,7 @@ FX_BOOL CPDF_StandardSecurityHandler::AES256_CheckPassword( if (copy_len > (uint32_t)perms.GetLength()) { copy_len = perms.GetLength(); } - FXSYS_memcpy(perms_buf, (const uint8_t*)perms, copy_len); + FXSYS_memcpy(perms_buf, perms.raw_str(), copy_len); uint8_t buf[16]; CRYPT_AESDecrypt(aes, buf, perms_buf, 16); FX_Free(aes); @@ -515,12 +515,12 @@ FX_BOOL CPDF_StandardSecurityHandler::CheckOwnerPassword( uint8_t* key, int32_t key_len) { CFX_ByteString user_pass = GetUserPassword(password, pass_size, key_len); - if (CheckUserPassword(user_pass, user_pass.GetLength(), FALSE, key, + if (CheckUserPassword(user_pass.raw_str(), user_pass.GetLength(), FALSE, key, key_len)) { return TRUE; } - return CheckUserPassword(user_pass, user_pass.GetLength(), TRUE, key, - key_len); + return CheckUserPassword(user_pass.raw_str(), user_pass.GetLength(), TRUE, + key, key_len); } FX_BOOL CPDF_StandardSecurityHandler::IsMetadataEncrypted() { return m_pEncryptDict->GetBooleanBy("EncryptMetadata", TRUE); @@ -652,14 +652,14 @@ void CPDF_StandardSecurityHandler::AES256_SetPassword( CFX_ByteString ukey = pEncryptDict->GetStringBy("U"); uint8_t digest1[48]; if (m_Revision >= 6) { - Revision6_Hash(password, size, digest, - (bOwner ? (const uint8_t*)ukey : NULL), digest1); + Revision6_Hash(password, size, digest, bOwner ? ukey.raw_str() : nullptr, + digest1); } else { CRYPT_SHA256Start(sha); CRYPT_SHA256Update(sha, password, size); CRYPT_SHA256Update(sha, digest, 8); if (bOwner) { - CRYPT_SHA256Update(sha, ukey, ukey.GetLength()); + CRYPT_SHA256Update(sha, ukey.raw_str(), ukey.GetLength()); } CRYPT_SHA256Finish(sha, digest1); } @@ -667,13 +667,13 @@ void CPDF_StandardSecurityHandler::AES256_SetPassword( pEncryptDict->SetAtString(bOwner ? "O" : "U", CFX_ByteString(digest1, 48)); if (m_Revision >= 6) { Revision6_Hash(password, size, digest + 8, - (bOwner ? (const uint8_t*)ukey : NULL), digest1); + bOwner ? ukey.raw_str() : nullptr, digest1); } else { CRYPT_SHA256Start(sha); CRYPT_SHA256Update(sha, password, size); CRYPT_SHA256Update(sha, digest + 8, 8); if (bOwner) { - CRYPT_SHA256Update(sha, ukey, ukey.GetLength()); + CRYPT_SHA256Update(sha, ukey.raw_str(), ukey.GetLength()); } CRYPT_SHA256Finish(sha, digest1); } diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h index 5e3cb45fba..0e3160a9d8 100644 --- a/core/fxcrt/include/fx_string.h +++ b/core/fxcrt/include/fx_string.h @@ -180,12 +180,6 @@ class CFX_ByteString { : nullptr; } - // Implicit conversion to uint8_t* -- deprecated. - operator const uint8_t*() const { - return m_pData ? reinterpret_cast(m_pData->m_String) - : nullptr; - } - // Explicit conversion to CFX_ByteStringC. // Note: |this| must outlive the use of the result. CFX_ByteStringC AsStringC() const { @@ -294,7 +288,7 @@ class CFX_ByteString { }; inline CFX_ByteStringC& CFX_ByteStringC::operator=(const CFX_ByteString& src) { - m_Ptr = (const uint8_t*)src; + m_Ptr = src.raw_str(); m_Length = src.GetLength(); return *this; } diff --git a/core/fxge/ge/fx_ge_fontmap.cpp b/core/fxge/ge/fx_ge_fontmap.cpp index 4ee2a22ae6..5ef58b5e79 100644 --- a/core/fxge/ge/fx_ge_fontmap.cpp +++ b/core/fxge/ge/fx_ge_fontmap.cpp @@ -751,7 +751,7 @@ void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) { if (name == m_LastFamily) { return; } - const uint8_t* ptr = name; + const uint8_t* ptr = name.raw_str(); FX_BOOL bLocalized = FALSE; for (int i = 0; i < name.GetLength(); i++) if (ptr[i] > 0x80) { @@ -1464,15 +1464,16 @@ void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path, return; } CFX_ByteString names = - FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616d65); + FPDF_LoadTableFromTT(pFile, tables.raw_str(), nTables, 0x6e616d65); if (names.IsEmpty()) { return; } - CFX_ByteString facename = GetNameFromTT(names, names.GetLength(), 1); + CFX_ByteString facename = + GetNameFromTT(names.raw_str(), names.GetLength(), 1); if (facename.IsEmpty()) { return; } - CFX_ByteString style = GetNameFromTT(names, names.GetLength(), 2); + CFX_ByteString style = GetNameFromTT(names.raw_str(), names.GetLength(), 2); if (style != "Regular") { facename += " " + style; } @@ -1481,9 +1482,10 @@ void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path, CFX_FontFaceInfo* pInfo = new CFX_FontFaceInfo(path, facename, tables, offset, filesize); - CFX_ByteString os2 = FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f32); + CFX_ByteString os2 = + FPDF_LoadTableFromTT(pFile, tables.raw_str(), nTables, 0x4f532f32); if (os2.GetLength() >= 86) { - const uint8_t* p = (const uint8_t*)os2 + 78; + const uint8_t* p = os2.raw_str() + 78; uint32_t codepages = GET_TT_LONG(p); if (codepages & (1 << 17)) { m_pMapper->AddInstalledFont(facename, FXFONT_SHIFTJIS_CHARSET); @@ -1603,8 +1605,7 @@ uint32_t CFX_FolderFontInfo::GetFontData(void* hFont, } else { uint32_t nTables = pFont->m_FontTables.GetLength() / 16; for (uint32_t i = 0; i < nTables; i++) { - const uint8_t* p = - static_cast(pFont->m_FontTables) + i * 16; + const uint8_t* p = pFont->m_FontTables.raw_str() + i * 16; if (GET_TT_LONG(p) == table) { offset = GET_TT_LONG(p + 8); datasize = GET_TT_LONG(p + 12); diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index 99f97d7ca2..54e606397f 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -201,7 +201,7 @@ void SetPageContents(CFX_ByteString key, CFX_ByteString sStream; sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); - pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, + pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); } return; @@ -220,8 +220,7 @@ void SetPageContents(CFX_ByteString key, CFX_ByteString sBody = CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); sStream = sStream + sBody + "\nQ"; - pContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, - FALSE); + pContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); pContentsArray->AddReference(pDocument, dwObjNum); break; } @@ -247,8 +246,7 @@ void SetPageContents(CFX_ByteString key, CFX_ByteString sStream; sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); - pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, - FALSE); + pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); } } @@ -508,9 +506,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, sFormName.c_str()); sStream += sTemp; - - pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, - FALSE); + pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); } pPageDict->RemoveAt("Annots"); diff --git a/xfa/fxfa/app/xfa_ffimageedit.cpp b/xfa/fxfa/app/xfa_ffimageedit.cpp index 344dfcddd9..18af171677 100644 --- a/xfa/fxfa/app/xfa_ffimageedit.cpp +++ b/xfa/fxfa/app/xfa_ffimageedit.cpp @@ -140,7 +140,7 @@ FX_BOOL CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, pFileRead->ReadBlock(pImageBuffer, 0, nDataSize); bsBuf.ReleaseBuffer(); if (!bsBuf.IsEmpty()) { - FX_CHAR* pData = XFA_Base64Encode(bsBuf, nDataSize); + FX_CHAR* pData = XFA_Base64Encode(bsBuf.raw_str(), nDataSize); wsImage = CFX_WideString::FromLocal(pData); FX_Free(pData); } diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index 0192c8b46c..ebe04f15c2 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -997,7 +997,7 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, } else { bsContent = CFX_ByteString::FromUnicode(wsImage); pImageFileRead = FX_CreateMemoryStream( - (uint8_t*)(const uint8_t*)bsContent, bsContent.GetLength()); + const_cast(bsContent.raw_str()), bsContent.GetLength()); } } else { CFX_WideString wsURL = wsHref; -- cgit v1.2.3