Skip to content

Commit 087bd05

Browse files
authored
Merge pull request #1062 from hashtopolis/bug/1061
Adding loops to scan through lines to support importing hashes longer then 1024 bytes
2 parents f4fc2b1 + 125e283 commit 087bd05

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/inc/utils/HashlistUtils.class.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,19 @@ public static function processZap($hashlistId, $separator, $source, $post, $file
346346
$startTime = time();
347347

348348
//find the line separator
349-
$buffer = fread($file, 1024);
350349
$lineSeparators = array("\r\n", "\n", "\r");
351350
$lineSeparator = "";
352-
foreach ($lineSeparators as $sep) {
353-
if (strpos($buffer, $sep) !== false) {
354-
$lineSeparator = $sep;
351+
352+
// This will loop through the buffer until it finds a line separator
353+
while (!feof($file)) {
354+
$buffer = fread($file, 1024);
355+
foreach ($lineSeparators as $ls) {
356+
if (strpos($buffer, $ls) !== false) {
357+
$lineSeparator = $ls;
358+
break;
359+
}
360+
}
361+
if (!empty($lineSeparator)) {
355362
break;
356363
}
357364
}
@@ -387,7 +394,18 @@ public static function processZap($hashlistId, $separator, $source, $post, $file
387394
$crackedIn[$l->getId()] = 0;
388395
}
389396
while (!feof($file)) {
390-
$data = stream_get_line($file, 1024, $lineSeparator);
397+
$data = '';
398+
while(($line = stream_get_line($file, 1024, $lineSeparator)) !== false){
399+
$data .= $line;
400+
// seek back the length of lineSeparator and check if it indeed was a line separator
401+
// If no lineSeperator was found, make sure not to check but just to keep reading
402+
if (strlen($lineSeparator) > 0) {
403+
fseek($file, strlen($lineSeparator) * -1, SEEK_CUR);
404+
if (fread($file, strlen($lineSeparator)) === $lineSeparator) {
405+
break;
406+
}
407+
}
408+
}
391409
if (strlen($data) == 0) {
392410
continue;
393411
}

0 commit comments

Comments
 (0)