| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" | 9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 CPDF_HintTables::~CPDF_HintTables() { | 26 CPDF_HintTables::~CPDF_HintTables() { |
| 27 m_dwDeltaNObjsArray.RemoveAll(); | 27 m_dwDeltaNObjsArray.RemoveAll(); |
| 28 m_dwNSharedObjsArray.RemoveAll(); | 28 m_dwNSharedObjsArray.RemoveAll(); |
| 29 m_dwSharedObjNumArray.RemoveAll(); | 29 m_dwSharedObjNumArray.RemoveAll(); |
| 30 m_dwIdentifierArray.RemoveAll(); | 30 m_dwIdentifierArray.RemoveAll(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 FX_DWORD CPDF_HintTables::GetItemLength( | 33 uint32_t CPDF_HintTables::GetItemLength( |
| 34 int index, | 34 int index, |
| 35 const std::vector<FX_FILESIZE>& szArray) { | 35 const std::vector<FX_FILESIZE>& szArray) { |
| 36 if (index < 0 || szArray.size() < 2 || | 36 if (index < 0 || szArray.size() < 2 || |
| 37 static_cast<size_t>(index) > szArray.size() - 2 || | 37 static_cast<size_t>(index) > szArray.size() - 2 || |
| 38 szArray[index] > szArray[index + 1]) { | 38 szArray[index] > szArray[index + 1]) { |
| 39 return 0; | 39 return 0; |
| 40 } | 40 } |
| 41 return szArray[index + 1] - szArray[index]; | 41 return szArray[index + 1] - szArray[index]; |
| 42 } | 42 } |
| 43 | 43 |
| 44 FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { | 44 FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { |
| 45 if (!hStream || hStream->IsEOF()) | 45 if (!hStream || hStream->IsEOF()) |
| 46 return FALSE; | 46 return FALSE; |
| 47 | 47 |
| 48 int nStreamOffset = ReadPrimaryHintStreamOffset(); | 48 int nStreamOffset = ReadPrimaryHintStreamOffset(); |
| 49 int nStreamLen = ReadPrimaryHintStreamLength(); | 49 int nStreamLen = ReadPrimaryHintStreamLength(); |
| 50 if (nStreamOffset < 0 || nStreamLen < 1) | 50 if (nStreamOffset < 0 || nStreamLen < 1) |
| 51 return FALSE; | 51 return FALSE; |
| 52 | 52 |
| 53 const FX_DWORD kHeaderSize = 288; | 53 const uint32_t kHeaderSize = 288; |
| 54 if (hStream->BitsRemaining() < kHeaderSize) | 54 if (hStream->BitsRemaining() < kHeaderSize) |
| 55 return FALSE; | 55 return FALSE; |
| 56 | 56 |
| 57 // Item 1: The least number of objects in a page. | 57 // Item 1: The least number of objects in a page. |
| 58 FX_DWORD dwObjLeastNum = hStream->GetBits(32); | 58 uint32_t dwObjLeastNum = hStream->GetBits(32); |
| 59 | 59 |
| 60 // Item 2: The location of the first page's page object. | 60 // Item 2: The location of the first page's page object. |
| 61 FX_DWORD dwFirstObjLoc = hStream->GetBits(32); | 61 uint32_t dwFirstObjLoc = hStream->GetBits(32); |
| 62 if (dwFirstObjLoc > nStreamOffset) { | 62 if (dwFirstObjLoc > nStreamOffset) { |
| 63 FX_SAFE_DWORD safeLoc = pdfium::base::checked_cast<FX_DWORD>(nStreamLen); | 63 FX_SAFE_DWORD safeLoc = pdfium::base::checked_cast<uint32_t>(nStreamLen); |
| 64 safeLoc += dwFirstObjLoc; | 64 safeLoc += dwFirstObjLoc; |
| 65 if (!safeLoc.IsValid()) | 65 if (!safeLoc.IsValid()) |
| 66 return FALSE; | 66 return FALSE; |
| 67 m_szFirstPageObjOffset = | 67 m_szFirstPageObjOffset = |
| 68 pdfium::base::checked_cast<FX_FILESIZE>(safeLoc.ValueOrDie()); | 68 pdfium::base::checked_cast<FX_FILESIZE>(safeLoc.ValueOrDie()); |
| 69 } else { | 69 } else { |
| 70 m_szFirstPageObjOffset = | 70 m_szFirstPageObjOffset = |
| 71 pdfium::base::checked_cast<FX_FILESIZE>(dwFirstObjLoc); | 71 pdfium::base::checked_cast<FX_FILESIZE>(dwFirstObjLoc); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Item 3: The number of bits needed to represent the difference | 74 // Item 3: The number of bits needed to represent the difference |
| 75 // between the greatest and least number of objects in a page. | 75 // between the greatest and least number of objects in a page. |
| 76 FX_DWORD dwDeltaObjectsBits = hStream->GetBits(16); | 76 uint32_t dwDeltaObjectsBits = hStream->GetBits(16); |
| 77 | 77 |
| 78 // Item 4: The least length of a page in bytes. | 78 // Item 4: The least length of a page in bytes. |
| 79 FX_DWORD dwPageLeastLen = hStream->GetBits(32); | 79 uint32_t dwPageLeastLen = hStream->GetBits(32); |
| 80 | 80 |
| 81 // Item 5: The number of bits needed to represent the difference | 81 // Item 5: The number of bits needed to represent the difference |
| 82 // between the greatest and least length of a page, in bytes. | 82 // between the greatest and least length of a page, in bytes. |
| 83 FX_DWORD dwDeltaPageLenBits = hStream->GetBits(16); | 83 uint32_t dwDeltaPageLenBits = hStream->GetBits(16); |
| 84 | 84 |
| 85 // Skip Item 6, 7, 8, 9 total 96 bits. | 85 // Skip Item 6, 7, 8, 9 total 96 bits. |
| 86 hStream->SkipBits(96); | 86 hStream->SkipBits(96); |
| 87 | 87 |
| 88 // Item 10: The number of bits needed to represent the greatest | 88 // Item 10: The number of bits needed to represent the greatest |
| 89 // number of shared object references. | 89 // number of shared object references. |
| 90 FX_DWORD dwSharedObjBits = hStream->GetBits(16); | 90 uint32_t dwSharedObjBits = hStream->GetBits(16); |
| 91 | 91 |
| 92 // Item 11: The number of bits needed to represent the numerically | 92 // Item 11: The number of bits needed to represent the numerically |
| 93 // greatest shared object identifier used by the pages. | 93 // greatest shared object identifier used by the pages. |
| 94 FX_DWORD dwSharedIdBits = hStream->GetBits(16); | 94 uint32_t dwSharedIdBits = hStream->GetBits(16); |
| 95 | 95 |
| 96 // Item 12: The number of bits needed to represent the numerator of | 96 // Item 12: The number of bits needed to represent the numerator of |
| 97 // the fractional position for each shared object reference. For each | 97 // the fractional position for each shared object reference. For each |
| 98 // shared object referenced from a page, there is an indication of | 98 // shared object referenced from a page, there is an indication of |
| 99 // where in the page's content stream the object is first referenced. | 99 // where in the page's content stream the object is first referenced. |
| 100 FX_DWORD dwSharedNumeratorBits = hStream->GetBits(16); | 100 uint32_t dwSharedNumeratorBits = hStream->GetBits(16); |
| 101 | 101 |
| 102 // Item 13: Skip Item 13 which has 16 bits. | 102 // Item 13: Skip Item 13 which has 16 bits. |
| 103 hStream->SkipBits(16); | 103 hStream->SkipBits(16); |
| 104 | 104 |
| 105 CPDF_Object* pPageNum = m_pLinearizedDict->GetElementValue("N"); | 105 CPDF_Object* pPageNum = m_pLinearizedDict->GetElementValue("N"); |
| 106 int nPages = pPageNum ? pPageNum->GetInteger() : 0; | 106 int nPages = pPageNum ? pPageNum->GetInteger() : 0; |
| 107 if (nPages < 1) | 107 if (nPages < 1) |
| 108 return FALSE; | 108 return FALSE; |
| 109 | 109 |
| 110 FX_SAFE_DWORD required_bits = dwDeltaObjectsBits; | 110 FX_SAFE_DWORD required_bits = dwDeltaObjectsBits; |
| 111 required_bits *= pdfium::base::checked_cast<FX_DWORD>(nPages); | 111 required_bits *= pdfium::base::checked_cast<uint32_t>(nPages); |
| 112 if (!CanReadFromBitStream(hStream, required_bits)) | 112 if (!CanReadFromBitStream(hStream, required_bits)) |
| 113 return FALSE; | 113 return FALSE; |
| 114 | 114 |
| 115 for (int i = 0; i < nPages; ++i) { | 115 for (int i = 0; i < nPages; ++i) { |
| 116 FX_SAFE_DWORD safeDeltaObj = hStream->GetBits(dwDeltaObjectsBits); | 116 FX_SAFE_DWORD safeDeltaObj = hStream->GetBits(dwDeltaObjectsBits); |
| 117 safeDeltaObj += dwObjLeastNum; | 117 safeDeltaObj += dwObjLeastNum; |
| 118 if (!safeDeltaObj.IsValid()) | 118 if (!safeDeltaObj.IsValid()) |
| 119 return FALSE; | 119 return FALSE; |
| 120 m_dwDeltaNObjsArray.Add(safeDeltaObj.ValueOrDie()); | 120 m_dwDeltaNObjsArray.Add(safeDeltaObj.ValueOrDie()); |
| 121 } | 121 } |
| 122 hStream->ByteAlign(); | 122 hStream->ByteAlign(); |
| 123 | 123 |
| 124 required_bits = dwDeltaPageLenBits; | 124 required_bits = dwDeltaPageLenBits; |
| 125 required_bits *= pdfium::base::checked_cast<FX_DWORD>(nPages); | 125 required_bits *= pdfium::base::checked_cast<uint32_t>(nPages); |
| 126 if (!CanReadFromBitStream(hStream, required_bits)) | 126 if (!CanReadFromBitStream(hStream, required_bits)) |
| 127 return FALSE; | 127 return FALSE; |
| 128 | 128 |
| 129 CFX_ArrayTemplate<FX_DWORD> dwPageLenArray; | 129 CFX_ArrayTemplate<uint32_t> dwPageLenArray; |
| 130 for (int i = 0; i < nPages; ++i) { | 130 for (int i = 0; i < nPages; ++i) { |
| 131 FX_SAFE_DWORD safePageLen = hStream->GetBits(dwDeltaPageLenBits); | 131 FX_SAFE_DWORD safePageLen = hStream->GetBits(dwDeltaPageLenBits); |
| 132 safePageLen += dwPageLeastLen; | 132 safePageLen += dwPageLeastLen; |
| 133 if (!safePageLen.IsValid()) | 133 if (!safePageLen.IsValid()) |
| 134 return FALSE; | 134 return FALSE; |
| 135 dwPageLenArray.Add(safePageLen.ValueOrDie()); | 135 dwPageLenArray.Add(safePageLen.ValueOrDie()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 CPDF_Object* pOffsetE = m_pLinearizedDict->GetElementValue("E"); | 138 CPDF_Object* pOffsetE = m_pLinearizedDict->GetElementValue("E"); |
| 139 int nOffsetE = pOffsetE ? pOffsetE->GetInteger() : -1; | 139 int nOffsetE = pOffsetE ? pOffsetE->GetInteger() : -1; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 163 } | 163 } |
| 164 | 164 |
| 165 if (nPages > 0) { | 165 if (nPages > 0) { |
| 166 m_szPageOffsetArray.push_back(m_szPageOffsetArray[nPages - 1] + | 166 m_szPageOffsetArray.push_back(m_szPageOffsetArray[nPages - 1] + |
| 167 dwPageLenArray[nPages - 1]); | 167 dwPageLenArray[nPages - 1]); |
| 168 } | 168 } |
| 169 hStream->ByteAlign(); | 169 hStream->ByteAlign(); |
| 170 | 170 |
| 171 // Number of shared objects. | 171 // Number of shared objects. |
| 172 required_bits = dwSharedObjBits; | 172 required_bits = dwSharedObjBits; |
| 173 required_bits *= pdfium::base::checked_cast<FX_DWORD>(nPages); | 173 required_bits *= pdfium::base::checked_cast<uint32_t>(nPages); |
| 174 if (!CanReadFromBitStream(hStream, required_bits)) | 174 if (!CanReadFromBitStream(hStream, required_bits)) |
| 175 return FALSE; | 175 return FALSE; |
| 176 | 176 |
| 177 for (int i = 0; i < nPages; i++) | 177 for (int i = 0; i < nPages; i++) |
| 178 m_dwNSharedObjsArray.Add(hStream->GetBits(dwSharedObjBits)); | 178 m_dwNSharedObjsArray.Add(hStream->GetBits(dwSharedObjBits)); |
| 179 hStream->ByteAlign(); | 179 hStream->ByteAlign(); |
| 180 | 180 |
| 181 // Array of identifiers, size = nshared_objects. | 181 // Array of identifiers, size = nshared_objects. |
| 182 for (int i = 0; i < nPages; i++) { | 182 for (int i = 0; i < nPages; i++) { |
| 183 required_bits = dwSharedIdBits; | 183 required_bits = dwSharedIdBits; |
| 184 required_bits *= m_dwNSharedObjsArray[i]; | 184 required_bits *= m_dwNSharedObjsArray[i]; |
| 185 if (!CanReadFromBitStream(hStream, required_bits)) | 185 if (!CanReadFromBitStream(hStream, required_bits)) |
| 186 return FALSE; | 186 return FALSE; |
| 187 | 187 |
| 188 for (int j = 0; j < m_dwNSharedObjsArray[i]; j++) | 188 for (int j = 0; j < m_dwNSharedObjsArray[i]; j++) |
| 189 m_dwIdentifierArray.Add(hStream->GetBits(dwSharedIdBits)); | 189 m_dwIdentifierArray.Add(hStream->GetBits(dwSharedIdBits)); |
| 190 } | 190 } |
| 191 hStream->ByteAlign(); | 191 hStream->ByteAlign(); |
| 192 | 192 |
| 193 for (int i = 0; i < nPages; i++) { | 193 for (int i = 0; i < nPages; i++) { |
| 194 FX_SAFE_DWORD safeSize = m_dwNSharedObjsArray[i]; | 194 FX_SAFE_DWORD safeSize = m_dwNSharedObjsArray[i]; |
| 195 safeSize *= dwSharedNumeratorBits; | 195 safeSize *= dwSharedNumeratorBits; |
| 196 if (!CanReadFromBitStream(hStream, safeSize)) | 196 if (!CanReadFromBitStream(hStream, safeSize)) |
| 197 return FALSE; | 197 return FALSE; |
| 198 | 198 |
| 199 hStream->SkipBits(safeSize.ValueOrDie()); | 199 hStream->SkipBits(safeSize.ValueOrDie()); |
| 200 } | 200 } |
| 201 hStream->ByteAlign(); | 201 hStream->ByteAlign(); |
| 202 | 202 |
| 203 FX_SAFE_DWORD safeTotalPageLen = pdfium::base::checked_cast<FX_DWORD>(nPages); | 203 FX_SAFE_DWORD safeTotalPageLen = pdfium::base::checked_cast<uint32_t>(nPages); |
| 204 safeTotalPageLen *= dwDeltaPageLenBits; | 204 safeTotalPageLen *= dwDeltaPageLenBits; |
| 205 if (!CanReadFromBitStream(hStream, safeTotalPageLen)) | 205 if (!CanReadFromBitStream(hStream, safeTotalPageLen)) |
| 206 return FALSE; | 206 return FALSE; |
| 207 | 207 |
| 208 hStream->SkipBits(safeTotalPageLen.ValueOrDie()); | 208 hStream->SkipBits(safeTotalPageLen.ValueOrDie()); |
| 209 hStream->ByteAlign(); | 209 hStream->ByteAlign(); |
| 210 return TRUE; | 210 return TRUE; |
| 211 } | 211 } |
| 212 | 212 |
| 213 FX_BOOL CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, | 213 FX_BOOL CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, |
| 214 FX_DWORD offset) { | 214 uint32_t offset) { |
| 215 if (!hStream || hStream->IsEOF()) | 215 if (!hStream || hStream->IsEOF()) |
| 216 return FALSE; | 216 return FALSE; |
| 217 | 217 |
| 218 int nStreamOffset = ReadPrimaryHintStreamOffset(); | 218 int nStreamOffset = ReadPrimaryHintStreamOffset(); |
| 219 int nStreamLen = ReadPrimaryHintStreamLength(); | 219 int nStreamLen = ReadPrimaryHintStreamLength(); |
| 220 if (nStreamOffset < 0 || nStreamLen < 1) | 220 if (nStreamOffset < 0 || nStreamLen < 1) |
| 221 return FALSE; | 221 return FALSE; |
| 222 | 222 |
| 223 FX_SAFE_DWORD bit_offset = offset; | 223 FX_SAFE_DWORD bit_offset = offset; |
| 224 bit_offset *= 8; | 224 bit_offset *= 8; |
| 225 if (!bit_offset.IsValid() || hStream->GetPos() > bit_offset.ValueOrDie()) | 225 if (!bit_offset.IsValid() || hStream->GetPos() > bit_offset.ValueOrDie()) |
| 226 return FALSE; | 226 return FALSE; |
| 227 hStream->SkipBits(bit_offset.ValueOrDie() - hStream->GetPos()); | 227 hStream->SkipBits(bit_offset.ValueOrDie() - hStream->GetPos()); |
| 228 | 228 |
| 229 const FX_DWORD kHeaderSize = 192; | 229 const uint32_t kHeaderSize = 192; |
| 230 if (hStream->BitsRemaining() < kHeaderSize) | 230 if (hStream->BitsRemaining() < kHeaderSize) |
| 231 return FALSE; | 231 return FALSE; |
| 232 | 232 |
| 233 // Item 1: The object number of the first object in the shared objects | 233 // Item 1: The object number of the first object in the shared objects |
| 234 // section. | 234 // section. |
| 235 FX_DWORD dwFirstSharedObjNum = hStream->GetBits(32); | 235 uint32_t dwFirstSharedObjNum = hStream->GetBits(32); |
| 236 | 236 |
| 237 // Item 2: The location of the first object in the shared objects section. | 237 // Item 2: The location of the first object in the shared objects section. |
| 238 FX_DWORD dwFirstSharedObjLoc = hStream->GetBits(32); | 238 uint32_t dwFirstSharedObjLoc = hStream->GetBits(32); |
| 239 if (dwFirstSharedObjLoc > nStreamOffset) | 239 if (dwFirstSharedObjLoc > nStreamOffset) |
| 240 dwFirstSharedObjLoc += nStreamLen; | 240 dwFirstSharedObjLoc += nStreamLen; |
| 241 | 241 |
| 242 // Item 3: The number of shared object entries for the first page. | 242 // Item 3: The number of shared object entries for the first page. |
| 243 m_nFirstPageSharedObjs = hStream->GetBits(32); | 243 m_nFirstPageSharedObjs = hStream->GetBits(32); |
| 244 | 244 |
| 245 // Item 4: The number of shared object entries for the shared objects | 245 // Item 4: The number of shared object entries for the shared objects |
| 246 // section, including the number of shared object entries for the first page. | 246 // section, including the number of shared object entries for the first page. |
| 247 FX_DWORD dwSharedObjTotal = hStream->GetBits(32); | 247 uint32_t dwSharedObjTotal = hStream->GetBits(32); |
| 248 | 248 |
| 249 // Item 5: The number of bits needed to represent the greatest number of | 249 // Item 5: The number of bits needed to represent the greatest number of |
| 250 // objects in a shared object group. Skipped. | 250 // objects in a shared object group. Skipped. |
| 251 hStream->SkipBits(16); | 251 hStream->SkipBits(16); |
| 252 | 252 |
| 253 // Item 6: The least length of a shared object group in bytes. | 253 // Item 6: The least length of a shared object group in bytes. |
| 254 FX_DWORD dwGroupLeastLen = hStream->GetBits(32); | 254 uint32_t dwGroupLeastLen = hStream->GetBits(32); |
| 255 | 255 |
| 256 // Item 7: The number of bits needed to represent the difference between the | 256 // Item 7: The number of bits needed to represent the difference between the |
| 257 // greatest and least length of a shared object group, in bytes. | 257 // greatest and least length of a shared object group, in bytes. |
| 258 FX_DWORD dwDeltaGroupLen = hStream->GetBits(16); | 258 uint32_t dwDeltaGroupLen = hStream->GetBits(16); |
| 259 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); | 259 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); |
| 260 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; | 260 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; |
| 261 if (nFirstPageObjNum < 0) | 261 if (nFirstPageObjNum < 0) |
| 262 return FALSE; | 262 return FALSE; |
| 263 | 263 |
| 264 FX_DWORD dwPrevObjLen = 0; | 264 uint32_t dwPrevObjLen = 0; |
| 265 FX_DWORD dwCurObjLen = 0; | 265 uint32_t dwCurObjLen = 0; |
| 266 FX_SAFE_DWORD required_bits = dwSharedObjTotal; | 266 FX_SAFE_DWORD required_bits = dwSharedObjTotal; |
| 267 required_bits *= dwDeltaGroupLen; | 267 required_bits *= dwDeltaGroupLen; |
| 268 if (!CanReadFromBitStream(hStream, required_bits)) | 268 if (!CanReadFromBitStream(hStream, required_bits)) |
| 269 return FALSE; | 269 return FALSE; |
| 270 | 270 |
| 271 for (FX_DWORD i = 0; i < dwSharedObjTotal; ++i) { | 271 for (uint32_t i = 0; i < dwSharedObjTotal; ++i) { |
| 272 dwPrevObjLen = dwCurObjLen; | 272 dwPrevObjLen = dwCurObjLen; |
| 273 FX_SAFE_DWORD safeObjLen = hStream->GetBits(dwDeltaGroupLen); | 273 FX_SAFE_DWORD safeObjLen = hStream->GetBits(dwDeltaGroupLen); |
| 274 safeObjLen += dwGroupLeastLen; | 274 safeObjLen += dwGroupLeastLen; |
| 275 if (!safeObjLen.IsValid()) | 275 if (!safeObjLen.IsValid()) |
| 276 return FALSE; | 276 return FALSE; |
| 277 | 277 |
| 278 dwCurObjLen = safeObjLen.ValueOrDie(); | 278 dwCurObjLen = safeObjLen.ValueOrDie(); |
| 279 if (i < m_nFirstPageSharedObjs) { | 279 if (i < m_nFirstPageSharedObjs) { |
| 280 m_dwSharedObjNumArray.Add(nFirstPageObjNum + i); | 280 m_dwSharedObjNumArray.Add(nFirstPageObjNum + i); |
| 281 if (i == 0) | 281 if (i == 0) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 return FALSE; | 317 return FALSE; |
| 318 | 318 |
| 319 hStream->SkipBits(dwSharedObjTotal); | 319 hStream->SkipBits(dwSharedObjTotal); |
| 320 hStream->ByteAlign(); | 320 hStream->ByteAlign(); |
| 321 return TRUE; | 321 return TRUE; |
| 322 } | 322 } |
| 323 | 323 |
| 324 FX_BOOL CPDF_HintTables::GetPagePos(int index, | 324 FX_BOOL CPDF_HintTables::GetPagePos(int index, |
| 325 FX_FILESIZE& szPageStartPos, | 325 FX_FILESIZE& szPageStartPos, |
| 326 FX_FILESIZE& szPageLength, | 326 FX_FILESIZE& szPageLength, |
| 327 FX_DWORD& dwObjNum) { | 327 uint32_t& dwObjNum) { |
| 328 if (!m_pLinearizedDict) | 328 if (!m_pLinearizedDict) |
| 329 return FALSE; | 329 return FALSE; |
| 330 | 330 |
| 331 szPageStartPos = m_szPageOffsetArray[index]; | 331 szPageStartPos = m_szPageOffsetArray[index]; |
| 332 szPageLength = GetItemLength(index, m_szPageOffsetArray); | 332 szPageLength = GetItemLength(index, m_szPageOffsetArray); |
| 333 | 333 |
| 334 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetElementValue("P"); | 334 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetElementValue("P"); |
| 335 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0; | 335 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0; |
| 336 | 336 |
| 337 CPDF_Object* pFirstPageObjNum = m_pLinearizedDict->GetElementValue("O"); | 337 CPDF_Object* pFirstPageObjNum = m_pLinearizedDict->GetElementValue("O"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 358 int index, | 358 int index, |
| 359 IPDF_DataAvail::DownloadHints* pHints) { | 359 IPDF_DataAvail::DownloadHints* pHints) { |
| 360 if (!m_pLinearizedDict || !pHints) | 360 if (!m_pLinearizedDict || !pHints) |
| 361 return IPDF_DataAvail::DataError; | 361 return IPDF_DataAvail::DataError; |
| 362 | 362 |
| 363 CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetElementValue("P"); | 363 CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetElementValue("P"); |
| 364 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0; | 364 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0; |
| 365 if (index == nFirstAvailPage) | 365 if (index == nFirstAvailPage) |
| 366 return IPDF_DataAvail::DataAvailable; | 366 return IPDF_DataAvail::DataAvailable; |
| 367 | 367 |
| 368 FX_DWORD dwLength = GetItemLength(index, m_szPageOffsetArray); | 368 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray); |
| 369 // If two pages have the same offset, it should be treated as an error. | 369 // If two pages have the same offset, it should be treated as an error. |
| 370 if (!dwLength) | 370 if (!dwLength) |
| 371 return IPDF_DataAvail::DataError; | 371 return IPDF_DataAvail::DataError; |
| 372 | 372 |
| 373 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) | 373 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) |
| 374 return IPDF_DataAvail::DataNotAvailable; | 374 return IPDF_DataAvail::DataNotAvailable; |
| 375 | 375 |
| 376 // Download data of shared objects in the page. | 376 // Download data of shared objects in the page. |
| 377 FX_DWORD offset = 0; | 377 uint32_t offset = 0; |
| 378 for (int i = 0; i < index; ++i) | 378 for (int i = 0; i < index; ++i) |
| 379 offset += m_dwNSharedObjsArray[i]; | 379 offset += m_dwNSharedObjsArray[i]; |
| 380 | 380 |
| 381 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); | 381 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); |
| 382 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; | 382 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; |
| 383 if (nFirstPageObjNum < 0) | 383 if (nFirstPageObjNum < 0) |
| 384 return IPDF_DataAvail::DataError; | 384 return IPDF_DataAvail::DataError; |
| 385 | 385 |
| 386 FX_DWORD dwIndex = 0; | 386 uint32_t dwIndex = 0; |
| 387 FX_DWORD dwObjNum = 0; | 387 uint32_t dwObjNum = 0; |
| 388 for (int j = 0; j < m_dwNSharedObjsArray[index]; ++j) { | 388 for (int j = 0; j < m_dwNSharedObjsArray[index]; ++j) { |
| 389 dwIndex = m_dwIdentifierArray[offset + j]; | 389 dwIndex = m_dwIdentifierArray[offset + j]; |
| 390 if (dwIndex >= m_dwSharedObjNumArray.GetSize()) | 390 if (dwIndex >= m_dwSharedObjNumArray.GetSize()) |
| 391 return IPDF_DataAvail::DataNotAvailable; | 391 return IPDF_DataAvail::DataNotAvailable; |
| 392 | 392 |
| 393 dwObjNum = m_dwSharedObjNumArray[dwIndex]; | 393 dwObjNum = m_dwSharedObjNumArray[dwIndex]; |
| 394 if (dwObjNum >= nFirstPageObjNum && | 394 if (dwObjNum >= nFirstPageObjNum && |
| 395 dwObjNum < nFirstPageObjNum + m_nFirstPageSharedObjs) { | 395 dwObjNum < nFirstPageObjNum + m_nFirstPageSharedObjs) { |
| 396 continue; | 396 continue; |
| 397 } | 397 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 415 | 415 |
| 416 CPDF_Dictionary* pDict = pHintStream->GetDict(); | 416 CPDF_Dictionary* pDict = pHintStream->GetDict(); |
| 417 CPDF_Object* pOffset = pDict ? pDict->GetElement("S") : nullptr; | 417 CPDF_Object* pOffset = pDict ? pDict->GetElement("S") : nullptr; |
| 418 if (!pOffset || !pOffset->IsNumber()) | 418 if (!pOffset || !pOffset->IsNumber()) |
| 419 return FALSE; | 419 return FALSE; |
| 420 | 420 |
| 421 int shared_hint_table_offset = pOffset->GetInteger(); | 421 int shared_hint_table_offset = pOffset->GetInteger(); |
| 422 CPDF_StreamAcc acc; | 422 CPDF_StreamAcc acc; |
| 423 acc.LoadAllData(pHintStream); | 423 acc.LoadAllData(pHintStream); |
| 424 | 424 |
| 425 FX_DWORD size = acc.GetSize(); | 425 uint32_t size = acc.GetSize(); |
| 426 // The header section of page offset hint table is 36 bytes. | 426 // The header section of page offset hint table is 36 bytes. |
| 427 // The header section of shared object hint table is 24 bytes. | 427 // The header section of shared object hint table is 24 bytes. |
| 428 // Hint table has at least 60 bytes. | 428 // Hint table has at least 60 bytes. |
| 429 const FX_DWORD MIN_STREAM_LEN = 60; | 429 const uint32_t MIN_STREAM_LEN = 60; |
| 430 if (size < MIN_STREAM_LEN || shared_hint_table_offset <= 0 || | 430 if (size < MIN_STREAM_LEN || shared_hint_table_offset <= 0 || |
| 431 size < shared_hint_table_offset) { | 431 size < shared_hint_table_offset) { |
| 432 return FALSE; | 432 return FALSE; |
| 433 } | 433 } |
| 434 | 434 |
| 435 CFX_BitStream bs; | 435 CFX_BitStream bs; |
| 436 bs.Init(acc.GetData(), size); | 436 bs.Init(acc.GetData(), size); |
| 437 return ReadPageHintTable(&bs) && | 437 return ReadPageHintTable(&bs) && |
| 438 ReadSharedObjHintTable(&bs, pdfium::base::checked_cast<FX_DWORD>( | 438 ReadSharedObjHintTable(&bs, pdfium::base::checked_cast<uint32_t>( |
| 439 shared_hint_table_offset)); | 439 shared_hint_table_offset)); |
| 440 } | 440 } |
| 441 | 441 |
| 442 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { | 442 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { |
| 443 if (!m_pLinearizedDict) | 443 if (!m_pLinearizedDict) |
| 444 return -1; | 444 return -1; |
| 445 | 445 |
| 446 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 446 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
| 447 if (!pRange) | 447 if (!pRange) |
| 448 return -1; | 448 return -1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 461 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 461 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
| 462 if (!pRange) | 462 if (!pRange) |
| 463 return -1; | 463 return -1; |
| 464 | 464 |
| 465 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 465 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 466 if (!pStreamLen) | 466 if (!pStreamLen) |
| 467 return -1; | 467 return -1; |
| 468 | 468 |
| 469 return pStreamLen->GetInteger(); | 469 return pStreamLen->GetInteger(); |
| 470 } | 470 } |
| OLD | NEW |