This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -148,9 +148,7 @@ public function isValid($value, $file = null)
148
148
return false ;
149
149
}
150
150
151
- $ algos = array_unique (array_values ($ this ->getHash ()));
152
- $ hashes = array_unique (array_keys ($ this ->getHash ()));
153
-
151
+ $ algos = array_unique (array_values ($ this ->getHash ()));
154
152
foreach ($ algos as $ algorithm ) {
155
153
$ filehash = hash_file ($ algorithm , $ fileInfo ['file ' ]);
156
154
@@ -159,10 +157,8 @@ public function isValid($value, $file = null)
159
157
return false ;
160
158
}
161
159
162
- foreach ($ hashes as $ hash ) {
163
- if ($ filehash === $ hash ) {
164
- return true ;
165
- }
160
+ if (isset ($ this ->getHash ()[$ filehash ]) && $ this ->getHash ()[$ filehash ] === $ algorithm ) {
161
+ return true ;
166
162
}
167
163
}
168
164
Original file line number Diff line number Diff line change 10
10
namespace ZendTest \Validator \File ;
11
11
12
12
use PHPUnit \Framework \TestCase ;
13
- use Zend \Validator \File ;
14
13
use ReflectionProperty ;
15
14
use Zend \Validator \Exception \InvalidArgumentException ;
15
+ use Zend \Validator \File ;
16
16
17
17
/**
18
18
* Hash testbed
@@ -253,4 +253,21 @@ public function testInvalidHashProvidedInArrayFormat($hash)
253
253
$ this ->expectExceptionMessage ('Hash must be a string ' );
254
254
$ validator ->addHash ([$ hash ]);
255
255
}
256
+
257
+ public function testIntHash ()
258
+ {
259
+ $ validator = new File \Hash ('10713230 ' );
260
+
261
+ self ::assertTrue ($ validator ->isValid (__DIR__ . '/_files/crc32-int.pdf ' ));
262
+ }
263
+
264
+ public function testHashMustMatchWithTheAlgorithm ()
265
+ {
266
+ $ validator = new File \Hash ();
267
+ // swapped hashes for given algorithms
268
+ $ validator ->addHash (['6507f172bceb9ed0cc59246d41569c4d ' , 'algorithm ' => 'crc32 ' ]);
269
+ $ validator ->addHash (['10713230 ' , 'algorithm ' => 'md5 ' ]);
270
+
271
+ self ::assertFalse ($ validator ->isValid (__DIR__ . '/_files/crc32-int.pdf ' ));
272
+ }
256
273
}
You can’t perform that action at this time.
0 commit comments