Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 (void)client_data; | 22 (void)client_data; |
| 23 } | 23 } |
| 24 static void fx_info_callback(const char* msg, void* client_data) { | 24 static void fx_info_callback(const char* msg, void* client_data) { |
| 25 (void)client_data; | 25 (void)client_data; |
| 26 } | 26 } |
| 27 OPJ_SIZE_T opj_read_from_memory(void* p_buffer, | 27 OPJ_SIZE_T opj_read_from_memory(void* p_buffer, |
| 28 OPJ_SIZE_T nb_bytes, | 28 OPJ_SIZE_T nb_bytes, |
| 29 void* p_user_data) { | 29 void* p_user_data) { |
| 30 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | 30 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); |
| 31 if (!srcData || !srcData->src_data || srcData->src_size == 0) { | 31 if (!srcData || !srcData->src_data || srcData->src_size == 0) { |
| 32 return -1; | 32 return static_cast<OPJ_SIZE_T>(-1); |
|
dsinclair
2016/03/16 13:23:31
Can you add a TODO, this seems broken. OPJ_SIZE is
Wei Li
2016/03/16 17:51:31
Done.
Tom Sepez
2016/03/16 18:34:58
Probably ok along the lines of std::string::npos's
Wei Li
2016/03/17 02:24:05
Ack. I digged deeper and found that this is requir
Tom Sepez
2016/03/17 16:40:05
Acknowledged.
| |
| 33 } | 33 } |
| 34 // Reads at EOF return an error code. | 34 // Reads at EOF return an error code. |
| 35 if (srcData->offset >= srcData->src_size) { | 35 if (srcData->offset >= srcData->src_size) { |
| 36 return -1; | 36 return static_cast<OPJ_SIZE_T>(-1); |
| 37 } | 37 } |
| 38 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; | 38 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; |
| 39 OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; | 39 OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; |
| 40 memcpy(p_buffer, &srcData->src_data[srcData->offset], readlength); | 40 memcpy(p_buffer, &srcData->src_data[srcData->offset], readlength); |
| 41 srcData->offset += readlength; | 41 srcData->offset += readlength; |
| 42 return readlength; | 42 return readlength; |
| 43 } | 43 } |
| 44 OPJ_SIZE_T opj_write_from_memory(void* p_buffer, | 44 OPJ_SIZE_T opj_write_from_memory(void* p_buffer, |
| 45 OPJ_SIZE_T nb_bytes, | 45 OPJ_SIZE_T nb_bytes, |
| 46 void* p_user_data) { | 46 void* p_user_data) { |
| 47 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | 47 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); |
| 48 if (!srcData || !srcData->src_data || srcData->src_size == 0) { | 48 if (!srcData || !srcData->src_data || srcData->src_size == 0) { |
| 49 return -1; | 49 return static_cast<OPJ_SIZE_T>(-1); |
| 50 } | 50 } |
| 51 // Writes at EOF return an error code. | 51 // Writes at EOF return an error code. |
| 52 if (srcData->offset >= srcData->src_size) { | 52 if (srcData->offset >= srcData->src_size) { |
| 53 return -1; | 53 return static_cast<OPJ_SIZE_T>(-1); |
| 54 } | 54 } |
| 55 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; | 55 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; |
| 56 OPJ_SIZE_T writeLength = nb_bytes < bufferLength ? nb_bytes : bufferLength; | 56 OPJ_SIZE_T writeLength = nb_bytes < bufferLength ? nb_bytes : bufferLength; |
| 57 memcpy(&srcData->src_data[srcData->offset], p_buffer, writeLength); | 57 memcpy(&srcData->src_data[srcData->offset], p_buffer, writeLength); |
| 58 srcData->offset += writeLength; | 58 srcData->offset += writeLength; |
| 59 return writeLength; | 59 return writeLength; |
| 60 } | 60 } |
| 61 OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { | 61 OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { |
| 62 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | 62 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); |
| 63 if (!srcData || !srcData->src_data || srcData->src_size == 0) { | 63 if (!srcData || !srcData->src_data || srcData->src_size == 0) { |
| 64 return -1; | 64 return static_cast<OPJ_OFF_T>(-1); |
| 65 } | 65 } |
| 66 // Offsets are signed and may indicate a negative skip. Do not support this | 66 // Offsets are signed and may indicate a negative skip. Do not support this |
| 67 // because of the strange return convention where either bytes skipped or | 67 // because of the strange return convention where either bytes skipped or |
| 68 // -1 is returned. Following that convention, a successful relative seek of | 68 // -1 is returned. Following that convention, a successful relative seek of |
| 69 // -1 bytes would be required to to give the same result as the error case. | 69 // -1 bytes would be required to to give the same result as the error case. |
| 70 if (nb_bytes < 0) { | 70 if (nb_bytes < 0) { |
| 71 return -1; | 71 return static_cast<OPJ_OFF_T>(-1); |
| 72 } | 72 } |
| 73 // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd. | 73 // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd. |
| 74 uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes); | 74 uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes); |
| 75 // Additionally, the offset may take us beyond the range of a size_t (e.g. | 75 // Additionally, the offset may take us beyond the range of a size_t (e.g. |
| 76 // 32-bit platforms). If so, just clamp at EOF. | 76 // 32-bit platforms). If so, just clamp at EOF. |
| 77 if (unsignedNbBytes > | 77 if (unsignedNbBytes > |
| 78 std::numeric_limits<OPJ_SIZE_T>::max() - srcData->offset) { | 78 std::numeric_limits<OPJ_SIZE_T>::max() - srcData->offset) { |
| 79 srcData->offset = srcData->src_size; | 79 srcData->offset = srcData->src_size; |
| 80 } else { | 80 } else { |
| 81 OPJ_SIZE_T checkedNbBytes = static_cast<OPJ_SIZE_T>(unsignedNbBytes); | 81 OPJ_SIZE_T checkedNbBytes = static_cast<OPJ_SIZE_T>(unsignedNbBytes); |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 886 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, | 886 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
| 887 uint8_t* dest_data, | 887 uint8_t* dest_data, |
| 888 int pitch, | 888 int pitch, |
| 889 const std::vector<uint8_t>& offsets) { | 889 const std::vector<uint8_t>& offsets) { |
| 890 return pDecoder->Decode(dest_data, pitch, offsets); | 890 return pDecoder->Decode(dest_data, pitch, offsets); |
| 891 } | 891 } |
| 892 | 892 |
| 893 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { | 893 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
| 894 delete pDecoder; | 894 delete pDecoder; |
| 895 } | 895 } |
| OLD | NEW |