Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Conversation

@mondrake
Copy link
Contributor

Fixes #10.

Let's face it... these test files are badly broken in terms of IFD structure. This PR just captures exceptions thrown by DataWindow and skips parts of the processing, trying to load the rest of the file one way or another, but without trying to repair anything.

Copy link
Collaborator

@weberhofer weberhofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for analyzing those issues. IMHO it's good to skip broken structures if necessary.

src/PelIfd.php Outdated
try {
$this->sub[$type]->load($d, $o);
} catch (PelDataWindowOffsetException $e) {
unset($this->sub[$type]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you "unset" the array element a hole will be kept in the array. It could be a good idea to assign the new PelIfd object to a temporary object and insert it into the array only on access instead of removing it from the array.

} catch (Exception $e) {
$this->fail('Test should not throw exception: ' . $e->getMessage());
}
$jpeg = new PelJpeg($tmpfile);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please inline the filename here, too.


function testWindowOffsetExceptionIsCaught()
{
$tmpfile = dirname(__FILE__) . '/images/27303092-d9d72838-54f6-11e7-943c-78933f9c9fbe.jpg';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename that file to match it's name with the test. Could be bug1730993-2.jpg

function testThisDoesNotWorkAsExpected()
function testWindowWindowExceptionIsCaught()
{
$tmpfile = dirname(__FILE__) . '/images/bug1730993_tmp.jpg';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the "_tmp" part of the file name would be good...

Copy link
Collaborator

@weberhofer weberhofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some more or less cosmetic issues

} catch (Exception $e) {
$this->fail('Test should not throw exception: ' . $e->getMessage());
}
$jpeg = new PelJpeg($tmpfile);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove the "$jpeg =" part as it's not used later on.

function testWindowOffsetExceptionIsCaught()
{
$tmpfile = dirname(__FILE__) . '/images/27303092-d9d72838-54f6-11e7-943c-78933f9c9fbe.jpg';
$jpeg = new PelJpeg($tmpfile);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove the "$jpeg =" part as it's not used later on.

$jpeg = new PelJpeg($tmpfile);
}

function testWindowOffsetExceptionIsCaught()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@please declare the method "public"

class Bug1730993Test extends TestCase
{
function testThisDoesNotWorkAsExpected()
function testWindowWindowExceptionIsCaught()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please declare the method "public"

@mondrake
Copy link
Contributor Author

mondrake commented Nov 18, 2017

@weberhofer I did a bit more refactoring to tests - I hope this is ok. The idea is to have a single test class for broken images, rather than one per bug, and to name test methods in a way to make clear which bug they cover.

@weberhofer weberhofer merged commit 635a365 into pel:master Nov 18, 2017
@weberhofer
Copy link
Collaborator

Great! Thanks a lot!

@mondrake mondrake deleted the patch-4 branch November 18, 2017 16:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants