Check if color exists in palette before using it

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Victor Dubiniuk 2017-01-31 23:13:40 +03:00 committed by Lukas Reschke
parent 69046c6662
commit 2585f195da
No known key found for this signature in database
GPG key ID: B9F6980CF6E759B1

View file

@ -760,12 +760,12 @@ class OC_Image implements \OCP\IImage {
break;
case 8:
$color = @unpack('n', $vide . substr($data, $p, 1));
$color[1] = $palette[$color[1] + 1];
$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
break;
case 4:
$color = @unpack('n', $vide . substr($data, floor($p), 1));
$color[1] = ($p * 2) % 2 == 0 ? $color[1] >> 4 : $color[1] & 0x0F;
$color[1] = $palette[$color[1] + 1];
$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
break;
case 1:
$color = @unpack('n', $vide . substr($data, floor($p), 1));
@ -795,7 +795,7 @@ class OC_Image implements \OCP\IImage {
$color[1] = ($color[1] & 0x1);
break;
}
$color[1] = $palette[$color[1] + 1];
$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
break;
default:
fclose($fh);