Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: core/src/fxcodec/codec/fx_codec_tiff.cpp

Issue 1425983002: XFA: remove unsafe exif parsing code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Null check. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcodec/codec/fx_codec.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxcodec/fx_codec.h" 7 #include "../../../include/fxcodec/fx_codec.h"
8 #include "../../../include/fxge/fx_dib.h" 8 #include "../../../include/fxge/fx_dib.h"
9 #include "codec_int.h" 9 #include "codec_int.h"
10 extern "C" { 10 extern "C" {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 TIFFGetField(tif_ctx, tag, &size, &buf); \ 249 TIFFGetField(tif_ctx, tag, &size, &buf); \
250 if (size && buf) { \ 250 if (size && buf) { \
251 (key) = FX_Alloc(uint8_t, size); \ 251 (key) = FX_Alloc(uint8_t, size); \
252 if ((key)) { \ 252 if ((key)) { \
253 FXSYS_memcpy((key), buf, size); \ 253 FXSYS_memcpy((key), buf, size); \
254 pExif->m_TagVal.SetAt(tag, (key)); \ 254 pExif->m_TagVal.SetAt(tag, (key)); \
255 } \ 255 } \
256 } \ 256 } \
257 } \ 257 } \
258 (key) = NULL; 258 (key) = NULL;
259
260 namespace {
261
259 template <class T> 262 template <class T>
260 static FX_BOOL Tiff_Exif_GetInfo(TIFF* tif_ctx, 263 FX_BOOL Tiff_Exif_GetInfo(TIFF* tif_ctx, ttag_t tag, CFX_DIBAttribute* pAttr) {
261 ttag_t tag, 264 T val = 0;
262 CFX_DIBAttributeExif* pExif) {
263 uint8_t* key = NULL;
264 T val = (T)0;
265 TIFFGetField(tif_ctx, tag, &val); 265 TIFFGetField(tif_ctx, tag, &val);
266 if (val) { 266 if (!val)
267 (key) = FX_Alloc(uint8_t, sizeof(T)); 267 return FALSE;
268 if ((key) == NULL) { 268 T* ptr = FX_Alloc(T, 1);
269 return FALSE; 269 *ptr = val;
270 } 270 pAttr->m_Exif[tag] = (void*)ptr;
271 T* ptr = (T*)(key); 271 return TRUE;
272 *ptr = val;
273 pExif->m_TagVal.SetAt(tag, (key));
274 return TRUE;
275 }
276 return FALSE;
277 } 272 }
278 static void Tiff_Exif_GetStringInfo(TIFF* tif_ctx, 273 void Tiff_Exif_GetStringInfo(TIFF* tif_ctx,
279 ttag_t tag, 274 ttag_t tag,
280 CFX_DIBAttributeExif* pExif) { 275 CFX_DIBAttribute* pAttr) {
281 FX_CHAR* buf = NULL; 276 FX_CHAR* buf = nullptr;
282 uint8_t* key = NULL;
283 TIFFGetField(tif_ctx, tag, &buf); 277 TIFFGetField(tif_ctx, tag, &buf);
284 if (buf) { 278 if (!buf)
285 int32_t size = (int32_t)FXSYS_strlen(buf); 279 return;
286 (key) = FX_Alloc(uint8_t, size + 1); 280 FX_STRSIZE size = FXSYS_strlen(buf);
287 if ((key) == NULL) { 281 uint8_t* ptr = FX_Alloc(uint8_t, size + 1);
288 return; 282 FXSYS_memcpy(ptr, buf, size);
289 } 283 ptr[size] = 0;
290 FXSYS_memcpy((key), buf, size); 284 pAttr->m_Exif[tag] = ptr;
291 key[size] = 0;
292 pExif->m_TagVal.SetAt(tag, (key));
293 }
294 } 285 }
286
287 } // namespace
288
295 FX_BOOL CCodec_TiffContext::LoadFrameInfo(int32_t frame, 289 FX_BOOL CCodec_TiffContext::LoadFrameInfo(int32_t frame,
296 FX_DWORD& width, 290 FX_DWORD& width,
297 FX_DWORD& height, 291 FX_DWORD& height,
298 FX_DWORD& comps, 292 FX_DWORD& comps,
299 FX_DWORD& bpc, 293 FX_DWORD& bpc,
300 CFX_DIBAttribute* pAttribute) { 294 CFX_DIBAttribute* pAttribute) {
301 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) { 295 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) {
302 return FALSE; 296 return FALSE;
303 } 297 }
304 FX_WORD tif_cs; 298 FX_WORD tif_cs;
(...skipping 10 matching lines...) Expand all
315 TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &tif_cs); 309 TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &tif_cs);
316 TIFFGetField(tif_ctx, TIFFTAG_COMPRESSION, &tif_cps); 310 TIFFGetField(tif_ctx, TIFFTAG_COMPRESSION, &tif_cps);
317 TIFFGetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, &tif_rps); 311 TIFFGetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, &tif_rps);
318 TIFFGetField(tif_ctx, TIFFTAG_ICCPROFILE, &tif_icc_size, &tif_icc_buf); 312 TIFFGetField(tif_ctx, TIFFTAG_ICCPROFILE, &tif_icc_size, &tif_icc_buf);
319 if (pAttribute) { 313 if (pAttribute) {
320 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_INCH; 314 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_INCH;
321 if (TIFFGetField(tif_ctx, TIFFTAG_RESOLUTIONUNIT, 315 if (TIFFGetField(tif_ctx, TIFFTAG_RESOLUTIONUNIT,
322 &pAttribute->m_wDPIUnit)) { 316 &pAttribute->m_wDPIUnit)) {
323 pAttribute->m_wDPIUnit -= 1; 317 pAttribute->m_wDPIUnit -= 1;
324 } 318 }
325 CFX_DIBAttributeExif* pExif = (CFX_DIBAttributeExif*)pAttribute->m_pExif; 319 Tiff_Exif_GetInfo<FX_WORD>(tif_ctx, TIFFTAG_ORIENTATION, pAttribute);
326 pExif->clear(); 320 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_XRESOLUTION, pAttribute)) {
327 Tiff_Exif_GetInfo<FX_WORD>(tif_ctx, TIFFTAG_ORIENTATION, pExif); 321 void* val = pAttribute->m_Exif[TIFFTAG_XRESOLUTION];
328 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_XRESOLUTION, pExif)) { 322 FX_FLOAT fDpi = val ? *reinterpret_cast<FX_FLOAT*>(val) : 0;
329 FX_FLOAT fDpi = 0;
330 pExif->GetInfo(TIFFTAG_XRESOLUTION, &fDpi);
331 pAttribute->m_nXDPI = (int32_t)(fDpi + 0.5f); 323 pAttribute->m_nXDPI = (int32_t)(fDpi + 0.5f);
332 } 324 }
333 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_YRESOLUTION, pExif)) { 325 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_YRESOLUTION, pAttribute)) {
334 FX_FLOAT fDpi = 0; 326 void* val = pAttribute->m_Exif[TIFFTAG_YRESOLUTION];
335 pExif->GetInfo(TIFFTAG_YRESOLUTION, &fDpi); 327 FX_FLOAT fDpi = val ? *reinterpret_cast<FX_FLOAT*>(val) : 0;
336 pAttribute->m_nYDPI = (int32_t)(fDpi + 0.5f); 328 pAttribute->m_nYDPI = (int32_t)(fDpi + 0.5f);
337 } 329 }
338 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_IMAGEDESCRIPTION, pExif); 330 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_IMAGEDESCRIPTION, pAttribute);
339 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MAKE, pExif); 331 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MAKE, pAttribute);
340 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MODEL, pExif); 332 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MODEL, pAttribute);
341 } 333 }
342 bpc = tif_bpc; 334 bpc = tif_bpc;
343 if (tif_rps > height) { 335 if (tif_rps > height) {
344 TIFFSetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, tif_rps = height); 336 TIFFSetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, tif_rps = height);
345 } 337 }
346 return TRUE; 338 return TRUE;
347 } 339 }
348 void _TiffBGRA2RGBA(uint8_t* pBuf, int32_t pixel, int32_t spp) { 340 void _TiffBGRA2RGBA(uint8_t* pBuf, int32_t pixel, int32_t spp) {
349 register uint8_t tmp;
350 for (int32_t n = 0; n < pixel; n++) { 341 for (int32_t n = 0; n < pixel; n++) {
351 tmp = pBuf[0]; 342 uint8_t tmp = pBuf[0];
352 pBuf[0] = pBuf[2]; 343 pBuf[0] = pBuf[2];
353 pBuf[2] = tmp; 344 pBuf[2] = tmp;
354 pBuf += spp; 345 pBuf += spp;
355 } 346 }
356 } 347 }
357 FX_BOOL CCodec_TiffContext::isSupport(CFX_DIBitmap* pDIBitmap) { 348 FX_BOOL CCodec_TiffContext::isSupport(CFX_DIBitmap* pDIBitmap) {
358 if (TIFFIsTiled(tif_ctx)) { 349 if (TIFFIsTiled(tif_ctx)) {
359 return FALSE; 350 return FALSE;
360 } 351 }
361 uint16_t photometric; 352 uint16_t photometric;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 return pDecoder->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute); 545 return pDecoder->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute);
555 } 546 }
556 FX_BOOL CCodec_TiffModule::Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) { 547 FX_BOOL CCodec_TiffModule::Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) {
557 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; 548 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx;
558 return pDecoder->Decode(pDIBitmap); 549 return pDecoder->Decode(pDIBitmap);
559 } 550 }
560 void CCodec_TiffModule::DestroyDecoder(void* ctx) { 551 void CCodec_TiffModule::DestroyDecoder(void* ctx) {
561 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; 552 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx;
562 delete pDecoder; 553 delete pDecoder;
563 } 554 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698