Skip to content

Commit 1861e33

Browse files
committed
Fix for security vulnerability: Using the phar:// wrapper it was possible to trigger the unserialization of user provided data.
1 parent b32e75e commit 1861e33

File tree

6 files changed

+49
-32
lines changed

6 files changed

+49
-32
lines changed

CHANGELOG.TXT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
6.2.20
2+
- Fix for security vulnerability: Using the phar:// wrapper it was possible to trigger the unserialization of user provided data.
3+
14
6.2.19
25
- Merge various fixes for PHP 7.3 compatibility and security.
36

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tecnickcom/tcpdf",
3-
"version": "6.2.19",
3+
"version": "6.2.20",
44
"homepage": "http://www.tcpdf.org/",
55
"type": "library",
66
"description": "TCPDF is a PHP class for generating PDF documents and barcodes.",

include/tcpdf_fonts.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TCPDF_FONTS {
7070
* @public static
7171
*/
7272
public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false, $link=false) {
73-
if (!file_exists($fontfile)) {
73+
if (!TCPDF_STATIC::file_exists($fontfile)) {
7474
// Could not find file
7575
return false;
7676
}
@@ -95,7 +95,7 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
9595
$outpath = self::_getfontpath();
9696
}
9797
// check if this font already exist
98-
if (@file_exists($outpath.$font_name.'.php')) {
98+
if (@TCPDF_STATIC::file_exists($outpath.$font_name.'.php')) {
9999
// this font already exist (delete it from fonts folder to rebuild it)
100100
return $font_name;
101101
}
@@ -1543,11 +1543,11 @@ public static function _getfontpath() {
15431543
public static function getFontFullPath($file, $fontdir=false) {
15441544
$fontfile = '';
15451545
// search files on various directories
1546-
if (($fontdir !== false) AND @file_exists($fontdir.$file)) {
1546+
if (($fontdir !== false) AND @TCPDF_STATIC::file_exists($fontdir.$file)) {
15471547
$fontfile = $fontdir.$file;
1548-
} elseif (@file_exists(self::_getfontpath().$file)) {
1548+
} elseif (@TCPDF_STATIC::file_exists(self::_getfontpath().$file)) {
15491549
$fontfile = self::_getfontpath().$file;
1550-
} elseif (@file_exists($file)) {
1550+
} elseif (@TCPDF_STATIC::file_exists($file)) {
15511551
$fontfile = $file;
15521552
}
15531553
return $fontfile;

include/tcpdf_images.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ public static function _toJPEG($image, $quality, $tempfile) {
161161
*/
162162
public static function _parsejpeg($file) {
163163
// check if is a local file
164-
if (!@file_exists($file)) {
164+
if (!@TCPDF_STATIC::file_exists($file)) {
165165
// try to encode spaces on filename
166166
$tfile = str_replace(' ', '%20', $file);
167-
if (@file_exists($tfile)) {
167+
if (@TCPDF_STATIC::file_exists($tfile)) {
168168
$file = $tfile;
169169
}
170170
}

include/tcpdf_static.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TCPDF_STATIC {
5555
* Current TCPDF version.
5656
* @private static
5757
*/
58-
private static $tcpdf_version = '6.2.19';
58+
private static $tcpdf_version = '6.2.20';
5959

6060
/**
6161
* String alias for total number of pages.
@@ -1854,6 +1854,29 @@ public static function fopenLocal($filename, $mode) {
18541854
return fopen($filename, $mode);
18551855
}
18561856

1857+
/**
1858+
* Wrapper for file_exists.
1859+
* Checks whether a file or directory exists.
1860+
* Only allows some protocols and local files.
1861+
* @param filename (string) Path to the file or directory.
1862+
* @return Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
1863+
* @public static
1864+
*/
1865+
public static function file_exists($filename) {
1866+
if (strpos($filename, '://') > 0) {
1867+
$wrappers = stream_get_wrappers();
1868+
foreach ($wrappers as $wrapper) {
1869+
if (($wrapper === 'http') || ($wrapper === 'https')) {
1870+
continue;
1871+
}
1872+
if (stripos($filename, $wrapper.'://') === 0) {
1873+
return false;
1874+
}
1875+
}
1876+
}
1877+
return @file_exists($filename);
1878+
}
1879+
18571880
/**
18581881
* Reads entire file into a string.
18591882
* The file can be also an URL.
@@ -1914,8 +1937,10 @@ public static function fileGetContents($file) {
19141937
}
19151938
//
19161939
$alt = array_unique($alt);
1917-
//var_dump($alt);exit;//DEBUG
19181940
foreach ($alt as $path) {
1941+
if (!self::file_exists($path)) {
1942+
return false;
1943+
}
19191944
$ret = @file_get_contents($path);
19201945
if ($ret !== false) {
19211946
return $ret;
@@ -1949,8 +1974,6 @@ public static function fileGetContents($file) {
19491974
return false;
19501975
}
19511976

1952-
1953-
19541977
/**
19551978
* Get ULONG from string (Big Endian 32-bit unsigned integer).
19561979
* @param $str (string) string from where to extract value

tcpdf.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
//============================================================+
33
// File name : tcpdf.php
4-
// Version : 6.2.19
4+
// Version : 6.2.20
55
// Begin : 2002-08-03
66
// Last Update : 2018-09-14
77
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
@@ -104,7 +104,7 @@
104104
* Tools to encode your unicode fonts are on fonts/utils directory.</p>
105105
* @package com.tecnick.tcpdf
106106
* @author Nicola Asuni
107-
* @version 6.2.19
107+
* @version 6.2.20
108108
*/
109109

110110
// TCPDF configuration
@@ -128,7 +128,7 @@
128128
* 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.<br>
129129
* @package com.tecnick.tcpdf
130130
* @brief PHP class for generating PDF documents without requiring external extensions.
131-
* @version 6.2.19
131+
* @version 6.2.20
132132
* @author Nicola Asuni - info@tecnick.com
133133
* @IgnoreAnnotation("protected")
134134
* @IgnoreAnnotation("public")
@@ -4256,7 +4256,7 @@ public function AddFont($family, $style='', $fontfile='', $subset='default') {
42564256
// true when the font style variation is missing
42574257
$missing_style = false;
42584258
// search and include font file
4259-
if (TCPDF_STATIC::empty_string($fontfile) OR (!@file_exists($fontfile))) {
4259+
if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) {
42604260
// build a standard filenames for specified font
42614261
$tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
42624262
$fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
@@ -4268,7 +4268,7 @@ public function AddFont($family, $style='', $fontfile='', $subset='default') {
42684268
}
42694269
}
42704270
// include font file
4271-
if (!TCPDF_STATIC::empty_string($fontfile) AND (@file_exists($fontfile))) {
4271+
if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
42724272
include($fontfile);
42734273
} else {
42744274
$this->Error('Could not include font definition file: '.$family.'');
@@ -4809,19 +4809,19 @@ public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'),
48094809
$this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
48104810
if (!$this->pdfa_mode) {
48114811
if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
4812-
AND (@file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
4812+
AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
48134813
AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
48144814
$this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
48154815
}
48164816
}
48174817
// Add widgets annotation's icons
4818-
if (isset($opt['mk']['i']) AND @file_exists($opt['mk']['i'])) {
4818+
if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) {
48194819
$this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
48204820
}
4821-
if (isset($opt['mk']['ri']) AND @file_exists($opt['mk']['ri'])) {
4821+
if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) {
48224822
$this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
48234823
}
4824-
if (isset($opt['mk']['ix']) AND @file_exists($opt['mk']['ix'])) {
4824+
if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) {
48254825
$this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
48264826
}
48274827
}
@@ -6845,20 +6845,11 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig
68456845
$file = substr($file, 1);
68466846
$exurl = $file;
68476847
}
6848-
$wrappers = stream_get_wrappers();
6849-
foreach ($wrappers as $wrapper) {
6850-
if ($wrapper === 'http' || $wrapper === 'https') {
6851-
continue;
6852-
}
6853-
if (stripos($file, $wrapper.'://') === 0) {
6854-
$this->Error('Stream wrappers in file paths are not supported');
6855-
}
6856-
}
68576848
// check if is a local file
6858-
if (!@file_exists($file)) {
6849+
if (!@TCPDF_STATIC::file_exists($file)) {
68596850
// try to encode spaces on filename
68606851
$tfile = str_replace(' ', '%20', $file);
6861-
if (@file_exists($tfile)) {
6852+
if (@TCPDF_STATIC::file_exists($tfile)) {
68626853
$file = $tfile;
68636854
}
68646855
}

0 commit comments

Comments
 (0)