Skip to content

Commit

Permalink
bugfix: endless loop in exif.inf parsing
Browse files Browse the repository at this point in the history
This fixes an endless loop that occured when reading from an exif.inf
file that starts with an empty line.

Bug reported and patch to `functions/getExifDescription.php` submitted
by Roland Dieterich. Many thanks to Roland!

Co-authored-by: Roland Dieterich <dieterich@mpipz.mpg.de>
  • Loading branch information
Boris-de and dieterich committed Jan 26, 2024
1 parent 3b330e9 commit 2e8107d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ Mig - Changelog

## Version 1.7.2 (tbd)

### Notable changes

Fixed endless loop when reading from an exif.inf file that starts with an empty line.

### Other changes

Fixed warnings reported by psalm and phpstorm and replaced outdated constructs.

### Acknowledgements

A special thanks to Roland Dieterich <dieterich@mpipz.mpg.de> for reporting and fixing the bug in the exif.inf parsing.

## Version 1.7.1 (Sat, 17 Dec 2022)

### Notable changes
Expand Down
10 changes: 3 additions & 7 deletions functions/getExifDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
function getExifDescription ( $unsafe_currDir, $formatString )
{
global $mig_config;

$aperture = array ();
$day = array ();
$desc = array ();
Expand All @@ -22,12 +22,10 @@ function getExifDescription ( $unsafe_currDir, $formatString )

$localExifFilename = $mig_config['albumdir'] . "/$unsafe_currDir/exif.inf";
if (file_exists($localExifFilename)) {

$fname = NULL;
$file = fopen($localExifFilename, 'r');
$line = fgets($file, 4096); // get first line
while (!feof($file)) {

$line = fgets($file, 4096);
if (strpos($line, 'File name : ') === 0) {
$fname = str_replace('File name : ', '', $line);
$fname = chop($fname);
Expand Down Expand Up @@ -103,12 +101,10 @@ function getExifDescription ( $unsafe_currDir, $formatString )
$day[$fname] = $y;
$time[$fname] = $z;
}

$line = fgets($file, 4096);
}

fclose($file);

$unsafe_image = $mig_config['unsafe_image'];

if (!isset($knownFiles[$unsafe_image])) {
Expand Down
23 changes: 19 additions & 4 deletions test/GetExifDescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function testNoExifInfo()

public function test()
{
global $mig_config;
$this->set_mig_config_image('test.jpg');
$dir = $this->album_dir . '/foo';
$this->mkdir($dir);
Expand Down Expand Up @@ -55,7 +54,6 @@ public function test()

public function testEmptyFile()
{
global $mig_config;
$this->set_mig_config_image('test.jpg');
$dir = $this->album_dir . '/foo';
$this->mkdir($dir);
Expand All @@ -64,9 +62,27 @@ public function testEmptyFile()
getExifDescription('./foo', '%c %a %f %i %l %m %s %Y %M %D %T'));
}

public function testOnlyNewline()
{
$this->set_mig_config_image('test.jpg');
$dir = $this->album_dir . '/foo';
$this->mkdir($dir);
$this->touchWithContent($dir . '/exif.inf', "\n");
$this->assertEquals('',
getExifDescription('./foo', '%c %a %f %i %l %m %s %Y %M %D %T'));
}

public function testContentAfterEmptyLine()
{
$this->set_mig_config_image('test.jpg');
$dir = $this->album_dir . '/foo';
$this->mkdir($dir);
$this->touchWithContent($dir . '/exif.inf', "\nFile name : test.jpg\nCamera model : Canon EOS 70D");
$this->assertEquals('Canon EOS 70D', getExifDescription('./foo', '%m'));
}

public function testMultipleFiles()
{
global $mig_config;
$this->touchWithContent($this->album_dir . '/exif.inf', "File name : test1.jpg\n
Camera model : Canon EOS 70D\n
Date/Time : 2013:12:05 18:37:14\n
Expand Down Expand Up @@ -98,7 +114,6 @@ public function testMultipleFiles()

public function testFileNotInExifData()
{
global $mig_config;
$this->set_mig_config_image('not_existing.jpg');
$dir = $this->album_dir . '/foo';
$this->mkdir($dir);
Expand Down

0 comments on commit 2e8107d

Please sign in to comment.