From 0dc8571d1354b8c319510be625a446218449f532 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 11 May 2017 15:43:47 -0400 Subject: Do not use vector data() when it is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, all pointers were being initialized to 0. After raw pointers were changed to vectors, data() was used in some cases, but now no longer returns nullptr when it is supposed to. This CL fixes that. Bug: chromium:721417 Change-Id: Ia31b75b18dc17d7eed48538145fe5d0d59668843 Reviewed-on: https://pdfium-review.googlesource.com/5353 Reviewed-by: Tom Sepez Commit-Queue: Nicolás Peña --- core/fxcodec/codec/ccodec_gifmodule.cpp | 4 +++- core/fxcodec/lgif/cgifdecompressor.cpp | 17 ++++++++++++++++- core/fxcodec/lgif/fx_gif.cpp | 10 ++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/fxcodec/codec/ccodec_gifmodule.cpp b/core/fxcodec/codec/ccodec_gifmodule.cpp index 70f55ceaa8..983daa088f 100644 --- a/core/fxcodec/codec/ccodec_gifmodule.cpp +++ b/core/fxcodec/codec/ccodec_gifmodule.cpp @@ -54,7 +54,9 @@ GifDecodeStatus CCodec_GifModule::ReadHeader(FXGIF_Context* ctx, *width = ctx->m_Gif->width; *height = ctx->m_Gif->height; *pal_num = ctx->m_Gif->global_pal_num; - *pal_pp = ctx->m_Gif->m_GlobalPalette.data(); + *pal_pp = ctx->m_Gif->m_GlobalPalette.empty() + ? nullptr + : ctx->m_Gif->m_GlobalPalette.data(); *bg_index = ctx->m_Gif->bc_index; return GifDecodeStatus::Success; } diff --git a/core/fxcodec/lgif/cgifdecompressor.cpp b/core/fxcodec/lgif/cgifdecompressor.cpp index 073659fd1c..6e9352f0af 100644 --- a/core/fxcodec/lgif/cgifdecompressor.cpp +++ b/core/fxcodec/lgif/cgifdecompressor.cpp @@ -18,7 +18,22 @@ FXGIF_Context::FXGIF_Context() {} FXGIF_Context::~FXGIF_Context() {} CGifDecompressor::CGifDecompressor(FXGIF_Context* p, char* error_string) - : decode_status(GIF_D_STATUS_SIG), err_ptr(error_string), gif_context(p) {} + : global_pal_num(0), + img_row_offset(0), + img_row_avail_size(0), + avail_in(0), + decode_status(GIF_D_STATUS_SIG), + skip_size(0), + err_ptr(error_string), + gif_context(p), + next_in(nullptr), + width(0), + height(0), + bc_index(0), + pixel_aspect(0), + global_sort_flag(0), + global_color_resolution(0), + img_pass_num(0) {} CGifDecompressor::~CGifDecompressor() {} diff --git a/core/fxcodec/lgif/fx_gif.cpp b/core/fxcodec/lgif/fx_gif.cpp index e50e64a559..4248c88a01 100644 --- a/core/fxcodec/lgif/fx_gif.cpp +++ b/core/fxcodec/lgif/fx_gif.cpp @@ -510,12 +510,15 @@ GifDecodeStatus gif_load_frame(CGifDecompressor* gif_ptr, int32_t frame_num) { ? (2 << ((GifLF*)&gif_image_ptr->m_ImageInfo.local_flag)->pal_bits) : 0; gif_ptr->avail_in = 0; + GifPalette* pLocalPalette = gif_image_ptr->m_LocalPalettes.empty() + ? nullptr + : gif_image_ptr->m_LocalPalettes.data(); if (!gif_img_gce_ptr) { bool bRes = gif_ptr->GetRecordPosition( gif_image_ptr->image_data_pos, gif_image_ptr->m_ImageInfo.left, gif_image_ptr->m_ImageInfo.top, gif_image_ptr->m_ImageInfo.width, - gif_image_ptr->m_ImageInfo.height, loc_pal_num, - gif_image_ptr->m_LocalPalettes.data(), 0, 0, -1, 0, + gif_image_ptr->m_ImageInfo.height, loc_pal_num, pLocalPalette, 0, 0, + -1, 0, (bool)((GifLF*)&gif_image_ptr->m_ImageInfo.local_flag)->interlace); if (!bRes) { gif_image_ptr->m_ImageRowBuf.clear(); @@ -526,8 +529,7 @@ GifDecodeStatus gif_load_frame(CGifDecompressor* gif_ptr, int32_t frame_num) { bool bRes = gif_ptr->GetRecordPosition( gif_image_ptr->image_data_pos, gif_image_ptr->m_ImageInfo.left, gif_image_ptr->m_ImageInfo.top, gif_image_ptr->m_ImageInfo.width, - gif_image_ptr->m_ImageInfo.height, loc_pal_num, - gif_image_ptr->m_LocalPalettes.data(), + gif_image_ptr->m_ImageInfo.height, loc_pal_num, pLocalPalette, (int32_t)gif_image_ptr->m_ImageGCE->delay_time, (bool)((GifCEF*)&gif_image_ptr->m_ImageGCE->gce_flag)->user_input, ((GifCEF*)&gif_image_ptr->m_ImageGCE->gce_flag)->transparency -- cgit v1.2.3