Skip to content
Snippets Groups Projects
Commit 08904814 authored by Jared Hancock's avatar Jared Hancock
Browse files

tnef: Improve performance of checksum checks

Previously, the data blocks were inspected byte for byte. Now data blocks
are parsed 1k at a time. Fewer PHP function calls ultimately means faster
performance.
parent e628b2f4
No related branches found
No related tags found
No related merge requests found
......@@ -110,10 +110,13 @@ class TnefStreamReader implements Iterator {
}
function check($block) {
$sum = 0;
for ($i=0, $k=strlen($block['data']); $i < $k; $i++)
$sum += ord($block['data'][$i]);
if ($block['checksum'] != ($sum % 65536))
$sum = 0; $bytes = strlen($block['data']); $bs = 1024;
for ($i=0; $i < $bytes; $i+=$bs) {
$b = unpack('C*', substr($block['data'], $i, min($bs, $bytes-$i)));
$sum += array_sum($b);
$sum = $sum % 65536;
}
if ($block['checksum'] != $sum)
throw new TnefException('Corrupted block. Invalid checksum');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment