This file is indexed.

/usr/share/php/Horde/Image/Png.php is in php-horde-image 2.5.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<?php
/**
 * Copyright 2003-2017 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 *
 * @author    Mike Cochrane <mike@graftonhall.co.nz>
 * @category  Horde
 * @license   http://www.horde.org/licenses/lgpl21 LGPL-2.1
 * @package   Image
 */

/**
 * This class implements the Horde_Image API for PNG images.
 *
 * It mainly provides some utility functions, such as the ability to make
 * pixels or solid images for now.
 *
 * @author    Mike Cochrane <mike@graftonhall.co.nz>
 * @category  Horde
 * @copyright 2003-2017 Horde LLC
 * @license   http://www.horde.org/licenses/lgpl21 LGPL-2.1
 * @package   Image
 */
class Horde_Image_Png extends Horde_Image_Base
{
    /**
     * The array of pixel data.
     *
     * @var array
     */
    protected $_img = array();

    /**
     * Color depth (only 8 and 16 implemented).
     *
     * @var integer
     */
    protected $_colorDepth = 8;

    /**
     * Color type (only 2 (true color) implemented).
     *
     * @var integer
     */
    protected $_colorType = 2;

    /**
     * Compression method (0 is the only current valid value).
     *
     * @var integer
     */
    protected $_compressionMethod = 0;

    /**
     * Filter method (0 is the only current valid value).
     *
     * @var integer
     */
    protected $_filterMethod = 0;

    /**
     * Interlace method (only 0 (no interlace) implemented).
     *
     * @var integer
     */
    protected $_interlaceMethod = 0;

    /**
     * PNG image constructor.
     */
    public function __construct($params, $context = array())
    {
        parent::__construct($params, $context);

        if (!empty($params['width'])) {
            $this->rectangle(
                0, 0, $params['width'], $params['height'],
                $this->_background, $this->_background
            );
        }
    }

    /**
     * Returns the MIME type for this image.
     *
     * @return string  The MIME type for this image.
     */
    public function getContentType()
    {
        return 'image/png';
    }

    /**
     * Returns the raw data for this image.
     *
     * @return string  The raw image data.
     */
    public function raw()
    {
        return $this->_header()
            . $this->_IHDR()

            /* Say what created the image file. */
            . $this->_tEXt('Software', 'Horde_Image_Png')

            /* Set the last modified date/time. */
            . $this->_tIME()

            . $this->_IDAT()
            . $this->_IEND();
    }

    /**
     * Resets the image data to defaults.
     */
    public function reset()
    {
        parent::reset();
        $this->_img = array();
    }

    /**
     * Draws a rectangle.
     *
     * @param integer $x       The left x-coordinate of the rectangle.
     * @param integer $y       The top y-coordinate of the rectangle.
     * @param integer $width   The width of the rectangle.
     * @param integer $height  The height of the rectangle.
     * @param string $color    The line color of the rectangle.
     * @param string $fill     The color to fill the rectangle.
     */
    public function rectangle(
        $x, $y, $width, $height, $color = 'black', $fill = 'none'
    )
    {
        list($r, $g, $b) = Horde_Image::getRGB($color);
        if ($fill != 'none') {
            list($fR, $fG, $fB) = Horde_Image::getRGB($fill);
        }

        $x2 = $x + $width;
        $y2 = $y + $height;

        for ($h = $y; $h <= $y2; $h++) {
            for ($w = $x; $w <= $x2; $w++) {
                // See if we're on an edge.
                if ($w == $x || $h == $y || $w == $x2 || $h == $y2) {
                    $this->_img[$h][$w] = array('r' => $r, 'g' => $g, 'b' => $b);
                } elseif ($fill != 'none') {
                    $this->_img[$h][$w] = array('r' => $fR, 'g' => $fG, 'b' => $fB);
                }
            }
        }
    }

    /**
     * Creates the PNG file header.
     */
    protected function _header()
    {
        return pack('CCCCCCCC', 137, 80, 78, 71, 13, 10, 26, 10);
    }

    /**
     * Creates the IHDR block.
     */
    protected function _IHDR()
    {
        $data = pack(
            'a4NNCCCCC',
            'IHDR',
            $this->_width,
            $this->_height,
            $this->_colorDepth,
            $this->_colorType,
            $this->_compressionMethod,
            $this->_filterMethod,
            $this->_interlaceMethod
        );

        return pack(
            'Na' . strlen($data) . 'N',
            strlen($data) - 4,
            $data,
            crc32($data)
        );
    }

    /**
     * Creates the IEND block.
     */
    protected function _IEND()
    {
        $data = 'IEND';
        return pack(
            'Na' . strlen($data) . 'N',
            strlen($data) - 4,
            $data,
            crc32($data)
        );
    }

    /**
     * Creates the IDAT block.
     */
    protected function _IDAT()
    {
        $data = '';
        $prevscanline = null;
        $filter = 0;
        for ($i = 0; $i < $this->_height; $i++) {
            $scanline = array();
            $data .= chr($filter);
            for ($j = 0; $j < $this->_width; $j++) {
                if ($this->_colorDepth == 8) {
                    $scanline[$j] = pack(
                        'CCC',
                        $this->_img[$i][$j]['r'],
                        $this->_img[$i][$j]['g'],
                        $this->_img[$i][$j]['b']
                    );
                } elseif ($this->_colorDepth == 16) {
                    $scanline[$j] = pack(
                        'nnn',
                        $this->_img[$i][$j]['r'] << 8,
                        $this->_img[$i][$j]['g'] << 8,
                        $this->_img[$i][$j]['b'] << 8
                    );
                }

                if ($filter == 0) {
                    /* No Filter. */
                    $data .= $scanline[$j];
                } elseif ($filter == 2) {
                    /* Up Filter. */
                    $pixel = $scanline[$j] - $prevscanline[$j];
                    if ($this->_colorDepth == 8) {
                        $data .= pack(
                            'CCC',
                            $pixel >> 16,
                            ($pixel >> 8) & 0xFF,
                            $pixel & 0xFF
                        );
                    } elseif ($this->_colorDepth == 16) {
                        $data .= pack(
                            'nnn',
                            ($pixel >> 32),
                            ($pixel >> 16) & 0xFFFF,
                            $pixel & 0xFFFF
                        );
                    }
                }
            }
            $prevscanline = $scanline;
        }
        $compressed = gzdeflate($data, 9);

        $data = 'IDAT'
            . pack(
                'CCa' . strlen($compressed) . 'a4',
                0x78,
                0x01,
                $compressed,
                $this->_Adler32($data)
            );

        return pack(
            'Na' . strlen($data) . 'N',
            strlen($data) - 4,
            $data,
            crc32($data)
        );
    }

    /**
     * Creates the tEXt block.
     */
    protected function _tEXt($keyword, $text)
    {
        $data = 'tEXt' . $keyword . "\0" . $text;

        return pack(
            'Na' . strlen($data) . 'N',
            strlen($data) - 4,
            $data,
            crc32($data)
        );
    }

    /**
     * Creates the tIME block.
     *
     * @param integer $date  A timestamp.
     */
    protected function _tIME($date = null)
    {
        if (is_null($date)) {
            $date = time();
        }

        $data = 'tIME'
            . pack(
                'nCCCCC',
                intval(date('Y', $date)),
                intval(date('m', $date)),
                intval(date('j', $date)),
                intval(date('G', $date)),
                intval(date('i', $date)),
                intval(date('s', $date))
            );

        return pack(
            'Na' . strlen($data) . 'N',
            strlen($data) - 4,
            $data,
            crc32($data)
        );
    }

    /**
     * Calculates an Adler32 checksum for a string.
     */
    protected function _Adler32($input)
    {
        $s1 = 1;
        $s2 = 0;
        $iMax = strlen($input);
        for ($i = 0; $i < $iMax; $i++) {
            $s1 = ($s1 + ord($input[$i])) % 0xFFF1;
            $s2 = ($s2 + $s1) % 0xFFF1;
        }
        return pack('N', (($s2 << 16) | $s1));
    }

    /**
     * Requests a specific image from the collection of images.
     *
     * @param integer $index  The index to return
     *
     * @return Horde_Image_Png
     * @throws Horde_Image_Exception
     */
    public function getImageAtIndex($index)
    {
        if ($index > 0) {
            throw new Horde_Image_Exception('Image index out of bounds.');
        }
        return clone($this);
    }

    /**
     * Returns the number of image pages available in the image object.
     *
     * @return integer  The number of images.
     */
    public function getImagePageCount()
    {
        return 1;
    }

}