Skip to content

Commit f0546bd

Browse files
Till Bergerbsweeney
authored andcommitted
Fix more cases of potentially passing non-string to string functions
Ignore read or uncompress errors explicitly by treating a `false` return value as empty string. `BinaryStream::write()` already handles `false` values for `$data` by writing nothing, so this seems to be the original intention.
1 parent e359fc8 commit f0546bd

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

src/FontLib/BinaryStream.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,17 @@ public function skip($n) {
137137
fseek($this->f, $n, SEEK_CUR);
138138
}
139139

140+
/**
141+
* @param int $n The number of bytes to read
142+
*
143+
* @return string
144+
*/
140145
public function read($n) {
141146
if ($n < 1) {
142147
return "";
143148
}
144149

145-
return fread($this->f, $n);
150+
return (string) fread($this->f, $n);
146151
}
147152

148153
public function write($data, $length = null) {

src/FontLib/EOT/File.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ function parse() {
6161
// TODO Read font data ...
6262
}
6363

64-
/**
65-
* Little endian version of the read method
66-
*
67-
* @param int $n The number of bytes to read
68-
*
69-
* @return string
70-
*/
64+
/**
65+
* Little endian version of the read method
66+
*
67+
* @param int $n The number of bytes to read
68+
*
69+
* @return string
70+
*/
7171
public function read($n) {
7272
if ($n < 1) {
7373
return "";
7474
}
7575

76-
$string = fread($this->f, $n);
76+
$string = (string) fread($this->f, $n);
7777
$chunks = mb_str_split($string, 2, '8bit');
7878

7979
return implode("", $chunks);

src/FontLib/Table/DirectoryEntry.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class DirectoryEntry extends BinaryStream {
3636

3737
protected $origF;
3838

39+
/**
40+
* @param string $data
41+
*
42+
* @return int
43+
*/
3944
static function computeChecksum($data) {
4045
$len = mb_strlen($data, '8bit');
4146
$mod = $len % 4;

src/FontLib/WOFF/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function load($file) {
4646
$data = $this->read($entry->length);
4747

4848
if ($entry->length < $entry->origLength) {
49-
$data = gzuncompress($data);
49+
$data = (string) gzuncompress($data);
5050
}
5151

5252
// Prepare data ...

0 commit comments

Comments
 (0)