From 0c26f23abf85a358f07008b76e128f4367f52aaf Mon Sep 17 00:00:00 2001 From: nicolaasuni Date: Wed, 18 Sep 2013 19:42:19 +0100 Subject: [PATCH] 6.0.031 (2013-09-18) - Bug #836 "Optional EOL marker before endstream" was fixed. - Some additional controls were added to avoid "division by zero" error with badly formatted input. --- CHANGELOG.TXT | 4 +++ README.TXT | 4 +-- composer.json | 2 +- include/tcpdf_static.php | 2 +- tcpdf.php | 67 +++++++++++++++++++++++++++++++++------- tcpdf_parser.php | 8 ++--- 6 files changed, 67 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 477677e..529f473 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -1,3 +1,7 @@ +6.0.031 (2013-09-18) + - Bug #836 "Optional EOL marker before endstream" was fixed. + - Some additional controls were added to avoid "division by zero" error with badly formatted input. + 6.0.030 (2013-09-17) - Bug #835 "PDF417 and Cyrilic simbols" was fixed. diff --git a/README.TXT b/README.TXT index 86ee82d..98b9c25 100644 --- a/README.TXT +++ b/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 6.0.030 -Release date: 2013-09-17 +Version: 6.0.031 +Release date: 2013-09-18 Author: Nicola Asuni Copyright (c) 2002-2013: diff --git a/composer.json b/composer.json index b38b098..2f745dd 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tecnick.com/tcpdf", - "version": "6.0.030", + "version": "6.0.031", "homepage": "http://www.tcpdf.org/", "type": "library", "description": "TCPDF is a PHP class for generating PDF documents.", diff --git a/include/tcpdf_static.php b/include/tcpdf_static.php index b18bd34..a6fa611 100644 --- a/include/tcpdf_static.php +++ b/include/tcpdf_static.php @@ -55,7 +55,7 @@ class TCPDF_STATIC { * Current TCPDF version. * @private static */ - private static $tcpdf_version = '6.0.030'; + private static $tcpdf_version = '6.0.031'; /** * String alias for total number of pages. diff --git a/tcpdf.php b/tcpdf.php index 6e517dc..de552bc 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -1,7 +1,7 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 6.0.030 + * @version 6.0.031 */ // TCPDF configuration @@ -163,7 +163,7 @@ require_once(dirname(__FILE__).'/include/tcpdf_static.php'); * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.
* @package com.tecnick.tcpdf * @brief PHP class for generating PDF documents without requiring external extensions. - * @version 6.0.030 + * @version 6.0.031 * @author Nicola Asuni - info@tecnick.com */ class TCPDF { @@ -5381,7 +5381,7 @@ class TCPDF { // get string width without spaces $width = $this->GetStringWidth(str_replace(' ', '', $txt)); // calculate average space width - $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / $this->FontSize; + $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1); if ($this->font_stretching != 100) { // word spacing is affected by stretching $spacewidth /= ($this->font_stretching / 100); @@ -6698,10 +6698,16 @@ class TCPDF { if ($w <= 0) { // set maximum width $w = ($this->w - $this->lMargin - $this->rMargin); + if ($w <= 0) { + $w = 1; + } } if ($h <= 0) { // set maximum height $h = ($this->PageBreakTrigger - $this->tMargin); + if ($h <= 0) { + $h = 1; + } } // resize the block to be vertically contained on a single page or single column if ($fitonpage OR $this->AutoPageBreak) { @@ -13489,7 +13495,12 @@ class TCPDF { // calculate aproximatively the ratio between widths of aliases and replacements. $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}'; $rep = str_repeat(' ', $this->GetNumChars($ref)); - $wdiff = max(1, ($this->GetStringWidth($ref) / $this->GetStringWidth($rep))); + $wrep = $this->GetStringWidth($rep); + if ($wrep > 0) { + $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep)); + } else { + $wdiff = 1; + } $sdiff = sprintf('%F', $wdiff); $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}'; if ($this->isUnicodeFont()) { @@ -13924,6 +13935,9 @@ class TCPDF { public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') { $bars = explode(',', $colors); $numbars = count($bars); // number of bars to print + if ($numbars <= 0) { + return; + } // set bar measures if ($vertical) { $coords = array(0, 0, 0, 1); @@ -15016,9 +15030,12 @@ class TCPDF { // create new barcode object $barcodeobj = new TCPDFBarcode($code, $type); $arrcode = $barcodeobj->getBarcodeArray(); - if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] == 0)) { + if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) { $this->Error('Error in 1D barcode string'); } + if ($arrcode['maxh'] <= 0) { + $arrcode['maxh'] = 1; + } // set default values if (!isset($style['position'])) { $style['position'] = ''; @@ -15384,10 +15401,13 @@ class TCPDF { // number of barcode columns and rows $rows = $arrcode['num_rows']; $cols = $arrcode['num_cols']; + if (($rows <= 0) || ($cols <= 0)){ + $this->Error('Error in 2D barcode string'); + } // module width and height $mw = $style['module_width']; $mh = $style['module_height']; - if (($mw == 0) OR ($mh == 0)) { + if (($mw <= 0) OR ($mh <= 0)) { $this->Error('Error in 2D barcode string'); } // get max dimensions @@ -17437,6 +17457,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // calculate additional space to add to each existing space $spacewidth = ($mdiff / ($ns - $no)) * $this->k; + if ($this->FontSize <= 0) { + $this->FontSize = 1; + } $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize; if ($this->font_spacing != 0) { // fixed spacing mode @@ -17732,7 +17755,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->newline = true; } // table - if ($dom[$key]['value'] == 'table') { + if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) { // available page width if ($this->rtl) { $wtmp = $this->x - $this->lMargin; @@ -17787,7 +17810,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) { $tdborder = $dom[$key]['border']; } - $colspan = $dom[$key]['attribute']['colspan']; + $colspan = intval($dom[$key]['attribute']['colspan']); + if ($colspan <= 0) { + $colspan = 1; + } $old_cell_padding = $this->cell_padding; if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) { $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px'); @@ -21139,7 +21165,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $maxpage = max($maxpage, $outline['p']); } $fw = ($tw - $this->GetStringWidth($pagenum.$filler)); - $numfills = floor($fw / $this->GetStringWidth($filler)); + $wfiller = $this->GetStringWidth($filler); + if ($wfiller > 0) { + $numfills = floor($fw / $wfiller); + } else { + $numfills = 0; + } if ($numfills > 0) { $rowfill = str_repeat($filler, $numfills); } else { @@ -22087,7 +22118,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // check page for no-write regions and adapt page margins if necessary list($x, $y) = $this->checkPageRegions($h, $x, $y); $ow = $this->xobjects[$id]['w']; + if ($ow <= 0) { + $ow = 1; + } $oh = $this->xobjects[$id]['h']; + if ($oh <= 0) { + $oh = 1; + } // calculate template width and height on document if (($w <= 0) AND ($h <= 0)) { $w = $ow; @@ -22128,8 +22165,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // print XObject Template + Transformation matrix $this->StartTransform(); // translate and scale - $sx = ($w / $this->xobjects[$id]['w']); - $sy = ($h / $this->xobjects[$id]['h']); + $sx = ($w / $ow); + $sy = ($h / $oh); $tm = array(); $tm[0] = $sx; $tm[1] = 0; @@ -22496,6 +22533,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } } + if ($ow <= 0) { + $ow = 1; + } + if ($oh <= 0) { + $oh = 1; + } // calculate image width and height on document if (($w <= 0) AND ($h <= 0)) { // convert image size to document unit diff --git a/tcpdf_parser.php b/tcpdf_parser.php index cdf70f6..d3d8d45 100644 --- a/tcpdf_parser.php +++ b/tcpdf_parser.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 1.0.007 + * @version 1.0.008 */ // include class for decoding filters @@ -605,7 +605,7 @@ class TCPDF_PARSER { $offset += 6; if (preg_match('/^([\r]?[\n])/isU', substr($this->pdfdata, $offset), $matches) == 1) { $offset += strlen($matches[0]); - if (preg_match('/([\r]?[\n])(endstream)/isU', substr($this->pdfdata, $offset), $matches, PREG_OFFSET_CAPTURE) == 1) { + if (preg_match('/([\r]?[\n])?(endstream)[\x09\x0a\x0c\x0d\x20]/isU', substr($this->pdfdata, $offset), $matches, PREG_OFFSET_CAPTURE) == 1) { $objval = substr($this->pdfdata, $offset, $matches[0][1]); $offset += $matches[2][1]; }