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 "../../../include/fpdfapi/fpdf_page.h" | 7 #include "../../../include/fpdfapi/fpdf_page.h" |
8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
| 9 #include "../../../third_party/numerics/safe_conversions_impl.h" |
9 #include "pageint.h" | 10 #include "pageint.h" |
10 #include <limits.h> | 11 #include <limits.h> |
11 class CPDF_PSEngine; | 12 class CPDF_PSEngine; |
12 typedef enum {PSOP_ADD, PSOP_SUB, PSOP_MUL, PSOP_DIV, PSOP_IDIV, PSOP_MOD, | 13 typedef enum {PSOP_ADD, PSOP_SUB, PSOP_MUL, PSOP_DIV, PSOP_IDIV, PSOP_MOD, |
13 PSOP_NEG, PSOP_ABS, PSOP_CEILING, PSOP_FLOOR, PSOP_ROUND, PSOP_TRU
NCATE, | 14 PSOP_NEG, PSOP_ABS, PSOP_CEILING, PSOP_FLOOR, PSOP_ROUND, PSOP_TRU
NCATE, |
14 PSOP_SQRT, PSOP_SIN, PSOP_COS, PSOP_ATAN, PSOP_EXP, PSOP_LN, PSOP_
LOG, | 15 PSOP_SQRT, PSOP_SIN, PSOP_COS, PSOP_ATAN, PSOP_EXP, PSOP_LN, PSOP_
LOG, |
15 PSOP_CVI, PSOP_CVR, PSOP_EQ, PSOP_NE, PSOP_GT, PSOP_GE, PSOP_LT, P
SOP_LE, | 16 PSOP_CVI, PSOP_CVR, PSOP_EQ, PSOP_NE, PSOP_GT, PSOP_GE, PSOP_LT, P
SOP_LE, |
16 PSOP_AND, PSOP_OR, PSOP_XOR, PSOP_NOT, PSOP_BITSHIFT, PSOP_TRUE, P
SOP_FALSE, | 17 PSOP_AND, PSOP_OR, PSOP_XOR, PSOP_NOT, PSOP_BITSHIFT, PSOP_TRUE, P
SOP_FALSE, |
17 PSOP_IF, PSOP_IFELSE, PSOP_POP, PSOP_EXCH, PSOP_DUP, PSOP_COPY, | 18 PSOP_IF, PSOP_IFELSE, PSOP_POP, PSOP_EXCH, PSOP_DUP, PSOP_COPY, |
18 PSOP_INDEX, PSOP_ROLL, PSOP_PROC, PSOP_CONST | 19 PSOP_INDEX, PSOP_ROLL, PSOP_PROC, PSOP_CONST |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 encoded_input[i] = PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDoma
ins[i * 2 + 1], | 547 encoded_input[i] = PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDoma
ins[i * 2 + 1], |
547 m_pEncodeInfo[i].encode_min, m_pEncod
eInfo[i].encode_max); | 548 m_pEncodeInfo[i].encode_min, m_pEncod
eInfo[i].encode_max); |
548 index[i] = (int)encoded_input[i]; | 549 index[i] = (int)encoded_input[i]; |
549 if (index[i] < 0) { | 550 if (index[i] < 0) { |
550 index[i] = 0; | 551 index[i] = 0; |
551 } else if (index[i] > m_pEncodeInfo[i].sizes - 1) { | 552 } else if (index[i] > m_pEncodeInfo[i].sizes - 1) { |
552 index[i] = m_pEncodeInfo[i].sizes - 1; | 553 index[i] = m_pEncodeInfo[i].sizes - 1; |
553 } | 554 } |
554 pos += index[i] * blocksize[i]; | 555 pos += index[i] * blocksize[i]; |
555 } | 556 } |
556 int bitpos = pos * m_nBitsPerSample * m_nOutputs; | 557 FX_SAFE_INT32 bitpos = pos; |
| 558 bitpos *= m_nBitsPerSample; |
| 559 bitpos *= m_nOutputs; |
| 560 if (!bitpos.IsValid()) { |
| 561 return FALSE; |
| 562 } |
557 FX_LPCBYTE pSampleData = m_pSampleStream->GetData(); | 563 FX_LPCBYTE pSampleData = m_pSampleStream->GetData(); |
558 if (pSampleData == NULL) { | 564 if (pSampleData == NULL) { |
559 return FALSE; | 565 return FALSE; |
560 } | 566 } |
| 567 FX_SAFE_INT32 bitpos1 = m_nOutputs - 1 > 0 ? m_nOutputs - 1 : 0; |
| 568 bitpos1 *= m_nBitsPerSample; |
| 569 bitpos1 += bitpos.ValueOrDie(); |
| 570 if (!bitpos1.IsValid()) { |
| 571 return FALSE; |
| 572 } |
561 for (int j = 0; j < m_nOutputs; j ++) { | 573 for (int j = 0; j < m_nOutputs; j ++) { |
562 FX_DWORD sample = _GetBits32(pSampleData, bitpos + j * m_nBitsPerSample,
m_nBitsPerSample); | 574 FX_DWORD sample = _GetBits32(pSampleData, bitpos.ValueOrDie() + j * m_nB
itsPerSample, m_nBitsPerSample); |
563 FX_FLOAT encoded = (FX_FLOAT)sample; | 575 FX_FLOAT encoded = (FX_FLOAT)sample; |
564 for (int i = 0; i < m_nInputs; i ++) { | 576 for (int i = 0; i < m_nInputs; i ++) { |
565 if (index[i] == m_pEncodeInfo[i].sizes - 1) { | 577 if (index[i] == m_pEncodeInfo[i].sizes - 1) { |
566 if (index[i] == 0) { | 578 if (index[i] == 0) { |
567 encoded = encoded_input[i] * (FX_FLOAT)sample; | 579 encoded = encoded_input[i] * (FX_FLOAT)sample; |
568 } | 580 } |
569 } else { | 581 } else { |
570 int bitpos1 = bitpos + m_nBitsPerSample * m_nOutputs * blocksize
[i]; | 582 FX_SAFE_INT32 bitpos2 = blocksize[i]; |
571 FX_DWORD sample1 = _GetBits32(pSampleData, bitpos1 + j * m_nBits
PerSample, m_nBitsPerSample); | 583 bitpos2 += 1; |
| 584 bitpos2 *= m_nBitsPerSample; |
| 585 bitpos2 *= m_nOutputs; |
| 586 bitpos2 += bitpos.ValueOrDie(); |
| 587 if (!bitpos2.IsValid()) { |
| 588 return FALSE; |
| 589 } |
| 590 FX_DWORD sample1 = _GetBits32(pSampleData, bitpos2.ValueOrDie(),
m_nBitsPerSample); |
572 encoded += (encoded_input[i] - index[i]) * ((FX_FLOAT)sample1 -
(FX_FLOAT)sample); | 591 encoded += (encoded_input[i] - index[i]) * ((FX_FLOAT)sample1 -
(FX_FLOAT)sample); |
573 } | 592 } |
574 } | 593 } |
575 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, | 594 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, |
576 m_pDecodeInfo[j].decode_min, m_pDecodeInfo[
j].decode_max); | 595 m_pDecodeInfo[j].decode_min, m_pDecodeInfo[
j].decode_max); |
577 } | 596 } |
578 return TRUE; | 597 return TRUE; |
579 } | 598 } |
580 class CPDF_PSFunc : public CPDF_Function | 599 class CPDF_PSFunc : public CPDF_Function |
581 { | 600 { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 for (int i = 0; i < m_nOutputs; i ++) { | 895 for (int i = 0; i < m_nOutputs; i ++) { |
877 if (results[i] < m_pRanges[i * 2]) { | 896 if (results[i] < m_pRanges[i * 2]) { |
878 results[i] = m_pRanges[i * 2]; | 897 results[i] = m_pRanges[i * 2]; |
879 } else if (results[i] > m_pRanges[i * 2 + 1]) { | 898 } else if (results[i] > m_pRanges[i * 2 + 1]) { |
880 results[i] = m_pRanges[i * 2 + 1]; | 899 results[i] = m_pRanges[i * 2 + 1]; |
881 } | 900 } |
882 } | 901 } |
883 } | 902 } |
884 return TRUE; | 903 return TRUE; |
885 } | 904 } |
OLD | NEW |