summaryrefslogtreecommitdiffstats
path: root/modules/getid3/module.lib.data_hash.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/getid3/module.lib.data_hash.php')
-rw-r--r--modules/getid3/module.lib.data_hash.php60
1 files changed, 30 insertions, 30 deletions
diff --git a/modules/getid3/module.lib.data_hash.php b/modules/getid3/module.lib.data_hash.php
index 4ec541c6..00032db8 100644
--- a/modules/getid3/module.lib.data_hash.php
+++ b/modules/getid3/module.lib.data_hash.php
@@ -26,23 +26,23 @@
class getid3_lib_data_hash
{
-
+
private $getid3;
-
-
+
+
// constructer - calculate md5/sha1 data
public function __construct(getID3 $getid3, $algorithm) {
-
+
$this->getid3 = $getid3;
-
+
// Check algorithm
if (!preg_match('/^(md5|sha1)$/', $algorithm)) {
throw new getid3_exception('Unsupported algorithm, "'.$algorithm.'", in GetHashdata()');
}
-
-
+
+
//// Handle ogg vorbis files
-
+
if ((@$getid3->info['fileformat'] == 'ogg') && (@$getid3->info['audio']['dataformat'] == 'vorbis')) {
// We cannot get an identical md5_data value for Ogg files where the comments
@@ -66,11 +66,11 @@ class getid3_lib_data_hash
if ((bool)ini_get('safe_mode')) {
throw new getid3_exception('PHP running in Safe Mode - cannot make system call to vorbiscomment[.exe] needed for '.$algorithm.'_data.');
}
-
+
if (!preg_match('/^Vorbiscomment /', `vorbiscomment --version 2>&1`)) {
throw new getid3_exception('vorbiscomment[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');
}
-
+
// Prevent user from aborting script
$old_abort = ignore_user_abort(true);
@@ -80,13 +80,13 @@ class getid3_lib_data_hash
// Use vorbiscomment to make temp file without comments
$temp = tempnam('*', 'getID3');
-
+
$command_line = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg(realpath($getid3->filename)).' '.escapeshellarg($temp).' 2>&1';
// Error from vorbiscomment
if ($vorbis_comment_error = `$command_line`) {
throw new getid3_exception('System call to vorbiscomment[.exe] failed.');
- }
+ }
// Get hash of newly created file
$hash_function = $algorithm . '_file';
@@ -98,16 +98,16 @@ class getid3_lib_data_hash
// Reset abort setting
ignore_user_abort($old_abort);
-
+
// Return success
return true;
}
//// Handle other file formats
-
+
// Get hash from part of file
if (@$getid3->info['avdataoffset'] || (@$getid3->info['avdataend'] && @$getid3->info['avdataend'] < $getid3->info['filesize'])) {
-
+
if ((bool)ini_get('safe_mode')) {
$getid3->warning('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm.');
$hash_function = 'hash_file_partial_safe_mode';
@@ -115,52 +115,52 @@ class getid3_lib_data_hash
else {
$hash_function = 'hash_file_partial';
}
-
+
$getid3->info[$algorithm.'_data'] = $this->$hash_function($getid3->filename, $getid3->info['avdataoffset'], $getid3->info['avdataend'], $algorithm);
- }
-
+ }
+
// Get hash from whole file - use built-in md5_file() and sha1_file()
else {
$hash_function = $algorithm . '_file';
$getid3->info[$algorithm.'_data'] = $hash_function($getid3->filename);
}
}
-
-
-
+
+
+
// Return md5/sha1sum for a file from starting position to absolute end position
// Using windows system call
private function hash_file_partial($file, $offset, $end, $algorithm) {
-
+
// It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data
// Fall back to create-temp-file method:
if ($algorithm == 'sha1' && strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
}
-
+
// Check for presence of binaries and revert to safe mode if not found
if (!`head --version`) {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
}
-
+
if (!`tail --version`) {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
}
-
+
if (!`${algorithm}sum --version`) {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
- }
-
+ }
+
$size = $end - $offset;
$command_line = 'head -c'.$end.' '.escapeshellarg(realpath($file)).' | tail -c'.$size.' | '.$algorithm.'sum';
return substr(`$command_line`, 0, $algorithm == 'md5' ? 32 : 40);
}
-
-
+
+
// Return md5/sha1sum for a file from starting position to absolute end position
// Using slow safe_mode temp file
- private function hash_file_partial_safe_mode($file, $offset, $end, $algorithm) {
+ private function hash_file_partial_safe_mode($file, $offset, $end, $algorithm) {
// Attempt to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
if (($data_filename = tempnam('*', 'getID3')) === false) {