Added
Link Here
|
1 |
--- Net/DNS2/Cache/File.php.orig 2020-10-11 17:33:54 UTC |
2 |
+++ Net/DNS2/Cache/File.php |
3 |
@@ -44,10 +44,17 @@ class Net_DNS2_Cache_File extends Net_DNS2_Cache |
4 |
// |
5 |
// check that the file exists first |
6 |
// |
7 |
- if ( ($this->cache_opened == false) |
8 |
- && (file_exists($this->cache_file) == true) |
9 |
- && (filesize($this->cache_file) > 0) |
10 |
- ) { |
11 |
+ if ( ($this->cache_opened == false) && (file_exists($this->cache_file) == true) ) { |
12 |
+ |
13 |
+ // |
14 |
+ // check the file size |
15 |
+ // |
16 |
+ $file_size = filesize($this->cache_file); |
17 |
+ if ( ($file_size === false) || ($file_size <= 0) ) { |
18 |
+ |
19 |
+ return; |
20 |
+ } |
21 |
+ |
22 |
// |
23 |
// open the file for reading |
24 |
// |
25 |
@@ -62,7 +69,7 @@ class Net_DNS2_Cache_File extends Net_DNS2_Cache |
26 |
// |
27 |
// read the file contents |
28 |
// |
29 |
- $data = fread($fp, filesize($this->cache_file)); |
30 |
+ $data = fread($fp, $file_size); |
31 |
|
32 |
$decoded = null; |
33 |
|
34 |
@@ -137,29 +144,39 @@ class Net_DNS2_Cache_File extends Net_DNS2_Cache |
35 |
fseek($fp, 0, SEEK_SET); |
36 |
|
37 |
// |
38 |
- // read the file contents |
39 |
- // |
40 |
- $data = @fread($fp, filesize($this->cache_file)); |
41 |
- if ( ($data !== false) && (strlen($data) > 0) ) { |
42 |
+ // get the file size first; in PHP 8.0 fread() was changed to throw an exception if you try |
43 |
+ // and read 0 bytes from a file. |
44 |
+ // |
45 |
+ $file_size = @filesize($this->cache_file); |
46 |
|
47 |
+ if ( ($file_size !== false) && ($file_size > 0) ) { |
48 |
+ |
49 |
// |
50 |
- // unserialize and store the data |
51 |
+ // read the file contents |
52 |
// |
53 |
- $c = $this->cache_data; |
54 |
+ $data = @fread($fp, $file_size); |
55 |
+ |
56 |
+ if ( ($data !== false) && (strlen($data) > 0) ) { |
57 |
|
58 |
- $decoded = null; |
59 |
+ // |
60 |
+ // unserialize and store the data |
61 |
+ // |
62 |
+ $c = $this->cache_data; |
63 |
|
64 |
- if ($this->cache_serializer == 'json') { |
65 |
+ $decoded = null; |
66 |
|
67 |
- $decoded = json_decode($data, true); |
68 |
- } else { |
69 |
+ if ($this->cache_serializer == 'json') { |
70 |
|
71 |
- $decoded = unserialize($data); |
72 |
- } |
73 |
+ $decoded = json_decode($data, true); |
74 |
+ } else { |
75 |
+ |
76 |
+ $decoded = unserialize($data); |
77 |
+ } |
78 |
|
79 |
- if (is_array($decoded) == true) { |
80 |
+ if (is_array($decoded) == true) { |
81 |
|
82 |
- $this->cache_data = array_merge($c, $decoded); |
83 |
+ $this->cache_data = array_merge($c, $decoded); |
84 |
+ } |
85 |
} |
86 |
} |
87 |
|