From 09b05373edc48849dc1be43dece326aec0f9cd07 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 13 Mar 2015 17:23:02 +0100 Subject: [PATCH] validate resource's integrity before using it --- lib/private/image.php | 5 ++++- tests/lib/image.php | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/private/image.php b/lib/private/image.php index 317b6fde160..2484aeecc63 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -283,9 +283,12 @@ class OC_Image { } /** - * @return string Returns the raw image data. + * @return null|string Returns the raw image data. */ function data() { + if (!$this->valid()) { + return null; + } ob_start(); switch ($this->mimeType) { case "image/png": diff --git a/tests/lib/image.php b/tests/lib/image.php index e0009b9710e..0ee517100ad 100644 --- a/tests/lib/image.php +++ b/tests/lib/image.php @@ -144,6 +144,11 @@ class Test_Image extends \Test\TestCase { $this->assertEquals($expected, $img->data()); } + public function testDataNoResource() { + $img = new \OC_Image(); + $this->assertNull($img->data()); + } + /** * @depends testData */ -- 2.39.5