Skip to content

Commit

Permalink
Squash multiple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Mar 25, 2024
1 parent 8115ff6 commit 82fc97b
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 160 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
6.7.4 (2024-03-24)
- Upgrade tcpdf tag encryption algorithm.
- Fix regression issue #699.
- Fix security issue.
- [BREAKING CHANGE] The tcpdf HTML tag syntax has changed, see example_049.php.
- New K_ALLOWED_TCPDF_TAGS configuration constant to set the allowed methods for the tcdpf HTML tag.
- Raised minimum PHP version to PHP 5.5.0.

6.6.5 (2023-09-02)
- Fix corrupted file.
- Fix GitHub automation tests.
- Fix SPDX license ID (#591)
- Fix warning "array offset on value of type null" (#620)
- Improve the README about the status of this library (#589)
- Fix deprecation warning with PHP 8.1 (#614)
- Fixes for PHP 8.2 in tcpdf_fonts.php (#632)
- Fix some php 8+ edge cases (#630)
- Fix composite glyph output (#581)
- Fix "access array offset on value of type bool" with PDF/A (#583)
- Fix non-numeric value warning (#627)
- Fix issues with S25 barcode (#611)
- Fix return type annotations (#613)
- Fix some inconsistencies in type hints (#598)

6.6.2 (2022-12-17)
- Ensure pregSplit return type is always array.
- Add ability to run tests on various operating systems (#566)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

2002-2022 Nicola Asuni - Tecnick.com LTD
2002-2024 Nicola Asuni - Tecnick.com LTD

**********************************************************************
**********************************************************************
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

* **category** Library
* **author** Nicola Asuni <info@tecnick.com>
* **copyright** 2002-2022 Nicola Asuni - Tecnick.com LTD
* **copyright** 2002-2024 Nicola Asuni - Tecnick.com LTD
* **license** http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* **link** http://www.tcpdf.org
* **source** https://github.com/tecnickcom/TCPDF


## IMPORTANT
A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this version will not receive any additional development or support.
This version should be considered obsolete, new projects should use the new version as soon it will become stable.
## NOTE
A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this library is in support only mode.



Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.2
6.7.4
8 changes: 8 additions & 0 deletions config/tcpdf_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@
*/
define('K_TCPDF_CALLS_IN_HTML', false);

/**
* List of TCPDF methods that are allowed to be called using HTML syntax.
* Note: each method name must end with surrounded with | (pipe) character.
* The constant K_TCPDF_CALLS_IN_HTML must be set to true.
* IMPORTANT: For security reason, disable this feature if you are allowing user HTML content.
*/
define('K_ALLOWED_TCPDF_TAGS', '');

/**
* If true and PHP version is greater than 5, then the Error() method throw new exception instead of terminating the execution.
*/
Expand Down
8 changes: 8 additions & 0 deletions examples/config/tcpdf_config_alt.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@
*/
define('K_TCPDF_CALLS_IN_HTML', true);

/**
* List of TCPDF methods that are allowed to be called using HTML syntax.
* Note: each method name must end with surrounded with | (pipe) character.
* The constant K_TCPDF_CALLS_IN_HTML must be set to true.
* IMPORTANT: For security reason, disable this feature if you are allowing user HTML content.
*/
define('K_ALLOWED_TCPDF_TAGS', '|AddPage|Rect|SetDrawColor|write1DBarcode|');

/**
* If true and PHP version is greater than 5, then the Error() method throw new exception instead of terminating the execution.
*/
Expand Down
34 changes: 18 additions & 16 deletions examples/example_049.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//============================================================+
// File name : example_049.php
// Begin : 2009-04-03
// Last Update : 2014-12-10
// Last Update : 2024-03-18
//
// Description : Example 049 for TCPDF class
// WriteHTML with TCPDF callback functions
Expand Down Expand Up @@ -78,11 +78,11 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
IMPORTANT:
If you are printing user-generated content, tcpdf tag can be unsafe.
You can disable this tag by setting to false the K_TCPDF_CALLS_IN_HTML
constant on TCPDF configuration file.
If you are printing user-generated content, the tcpdf tag should be considered unsafe.
This tag is disabled by default by the K_TCPDF_CALLS_IN_HTML constant on TCPDF configuration file.
Please use this feature only if you are in control of the HTML content and you are sure that it does not contain any harmful code.
For security reasons, the parameters for the 'params' attribute of TCPDF
For security reasons, the parameters for the 'params' attribute of TCPDF
tag must be prepared as an array and encoded with the
serializeTCPDFtagParameters() method (see the example below).
Expand All @@ -91,23 +91,25 @@

$html = '<h1>Test TCPDF Methods in HTML</h1>
<h2 style="color:red;">IMPORTANT:</h2>
<span style="color:red;">If you are using user-generated content, the tcpdf tag can be unsafe.<br />
You can disable this tag by setting to false the <b>K_TCPDF_CALLS_IN_HTML</b> constant on TCPDF configuration file.</span>
<span style="color:red;">If you are using user-generated content, the tcpdf tag should be considered unsafe.<br />
Please use this feature only if you are in control of the HTML content and you are sure that it does not contain any harmful code.<br />
This feature is disabled by default by the <b>K_TCPDF_CALLS_IN_HTML</b> constant on TCPDF configuration file.</span>
<h2>write1DBarcode method in HTML</h2>';

$params = $pdf->serializeTCPDFtagParameters(array('CODE 39', 'C39', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
$html .= '<tcpdf method="write1DBarcode" params="'.$params.'" />';
$data = $pdf->serializeTCPDFtag('write1DBarcode', array('CODE 39', 'C39', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
$html .= '<tcpdf data="'.$data.'" />';

$params = $pdf->serializeTCPDFtagParameters(array('CODE 128', 'C128', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
$html .= '<tcpdf method="write1DBarcode" params="'.$params.'" />';
$data = $pdf->serializeTCPDFtag('write1DBarcode', array('CODE 128', 'C128', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
$html .= '<tcpdf data="'.$data.'" />';

$html .= '<tcpdf method="AddPage" /><h2>Graphic Functions</h2>';
$data = $pdf->serializeTCPDFtag('AddPage');
$html .= '<tcpdf data="'.$data.'" /><h2>Graphic Functions</h2>';

$params = $pdf->serializeTCPDFtagParameters(array(0));
$html .= '<tcpdf method="SetDrawColor" params="'.$params.'" />';
$data = $pdf->serializeTCPDFtag('SetDrawColor', array(0));
$html .= '<tcpdf data="'.$data.'" />';

$params = $pdf->serializeTCPDFtagParameters(array(50, 50, 40, 10, 'DF', array(), array(0,128,255)));
$html .= '<tcpdf method="Rect" params="'.$params.'" />';
$data = $pdf->serializeTCPDFtag('Rect', array(50, 50, 40, 10, 'DF', array(), array(0,128,255)));
$html .= '<tcpdf data="'.$data.'" />';


// output the HTML content
Expand Down
4 changes: 2 additions & 2 deletions examples/example_066.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* @group pdf
*/

// Load the autoloader, move one folder back from examples
require_once __DIR__ . '/../vendor/autoload.php';
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
Expand Down
1 change: 1 addition & 0 deletions include/barcodes/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ protected function getCode() {
if ($col >= $this->rsblocks[0]['dataLength']) {
$row += $this->b1;
}
$row = (int) $row;
$ret = $this->rsblocks[$row]['data'][$col];
} elseif ($this->count < $this->dataLength + $this->eccLength) {
$row = ($this->count - $this->dataLength) % $this->blocks;
Expand Down
50 changes: 25 additions & 25 deletions include/tcpdf_fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -1323,43 +1323,43 @@ public static function _getTrueTypeFontSubset($font, $subsetchars) {
// set the checkSumAdjustment to 0
$table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
}
$pad = 4 - ($table[$tag]['length'] % 4);
if ($pad != 4) {
// the length of a table must be a multiple of four bytes
$table[$tag]['length'] += $pad;
$table[$tag]['data'] .= str_repeat("\x0", $pad);
}
$table[$tag]['offset'] = $offset;
$offset += $table[$tag]['length'];
$numPad = ($offset + 3 & ~3) - $offset;
if($numPad > 0) {
$table[$tag]['data'] .= str_repeat("\x0", $numPad);
$offset += $numPad;
}
// check sum is not changed (so keep the following line commented)
//$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
//$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length'] + $numPad);
} else {
unset($table[$tag]);
}
}
// add loca
$table['loca'] = array();
$table['loca']['data'] = $loca;
$table['loca']['length'] = strlen($loca);
$pad = 4 - ($table['loca']['length'] % 4);
if ($pad != 4) {
// the length of a table must be a multiple of four bytes
$table['loca']['length'] += $pad;
$table['loca']['data'] .= str_repeat("\x0", $pad);
}
$table['loca']['offset'] = $offset;
$table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
$offset += $table['loca']['length'];
$numPad = ($offset + 3 & ~3) - $offset;
if($numPad > 0) {
$table['loca']['data'] .= str_repeat("\x0", $numPad);
$offset += $numPad;
}
$table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length'] + $numPad);
// add glyf
$table['glyf'] = array();
$table['glyf']['data'] = $glyf;
$table['glyf']['length'] = strlen($glyf);
$pad = 4 - ($table['glyf']['length'] % 4);
if ($pad != 4) {
// the length of a table must be a multiple of four bytes
$table['glyf']['length'] += $pad;
$table['glyf']['data'] .= str_repeat("\x0", $pad);
}
$table['glyf']['offset'] = $offset;
$table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
$offset += $table['glyf']['length'];
$numPad = ($offset + 3 & ~3) - $offset;
if($numPad > 0) {
$table['glyf']['data'] .= str_repeat("\x0", $numPad);
$offset += $numPad;
}
$table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length'] + $numPad);
// rebuild font
$font = '';
$font .= pack('N', 0x10000); // sfnt version
Expand All @@ -1383,7 +1383,7 @@ public static function _getTrueTypeFontSubset($font, $subsetchars) {
}
// set checkSumAdjustment on head table
$checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font));
$font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12);
$font = substr($font, 0, $table['head']['offset'] + $offset + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + $offset + 12);
return $font;
}

Expand Down Expand Up @@ -1780,9 +1780,9 @@ public static function arrUTF8ToUTF16BE($unicode, $setbom=false) {
*/
public static function UTF8ArrayToUniArray($ta, $isunicode=true) {
if ($isunicode) {
return array_map(array('TCPDF_FONTS', 'unichrUnicode'), $ta);
return array_map(get_called_class().'::unichrUnicode', $ta);
}
return array_map(array('TCPDF_FONTS', 'unichrASCII'), $ta);
return array_map(get_called_class().'::unichrASCII', $ta);
}

/**
Expand Down Expand Up @@ -2002,7 +2002,7 @@ public static function UTF8StringToArray($str, $isunicode, &$currentfont) {
if ($isunicode) {
// requires PCRE unicode support turned on
$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
$carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
$carr = array_map(get_called_class().'::uniord', $chars);
} else {
$chars = str_split($str);
$carr = array_map('ord', $chars);
Expand Down
10 changes: 5 additions & 5 deletions include/tcpdf_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// File name : tcpdf_static.php
// Version : 1.1.4
// Begin : 2002-08-03
// Last Update : 2022-08-12
// Last Update : 2023-09-06
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// -------------------------------------------------------------------
// Copyright (C) 2002-2022 Nicola Asuni - Tecnick.com LTD
// Copyright (C) 2002-2023 Nicola Asuni - Tecnick.com LTD
//
// This file is part of TCPDF software library.
//
Expand Down Expand Up @@ -55,7 +55,7 @@ class TCPDF_STATIC {
* Current TCPDF version.
* @private static
*/
private static $tcpdf_version = '6.6.2';
private static $tcpdf_version = '6.7.4';

/**
* String alias for total number of pages.
Expand Down Expand Up @@ -1780,7 +1780,7 @@ public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $f
if ($ret === false) {
return array();
}
return $ret;
return is_array($ret) ? $ret : array();
}
// preg_split is bugged - try alternative solution
$ret = array();
Expand Down Expand Up @@ -2124,7 +2124,7 @@ public static function _freadint($f) {
* Array of page formats
* measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4)
* @public static
*
*
* @var array<string,float[]>
*/
public static $page_formats = array(
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ parameters:
- ./
excludePaths:
- vendor/
# remove once https://github.com/phpstan/phpstan/issues/7955 is fixed
- fonts/
- tests/

scanFiles:
Expand Down
Loading

0 comments on commit 82fc97b

Please sign in to comment.