PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/standard - image.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 493 599 82.3 %
Date: 2014-12-15 Functions: 34 35 97.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
      16             :    |          Marcus Boerger <helly@php.net>                              |
      17             :    +----------------------------------------------------------------------+
      18             :  */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "php.h"
      23             : #include <stdio.h>
      24             : #if HAVE_FCNTL_H
      25             : #include <fcntl.h>
      26             : #endif
      27             : #include "fopen_wrappers.h"
      28             : #include "ext/standard/fsock.h"
      29             : #if HAVE_UNISTD_H
      30             : #include <unistd.h>
      31             : #endif
      32             : #include "php_image.h"
      33             : #ifdef PHP_WIN32
      34             : #include "win32/php_stdint.h"
      35             : #endif
      36             : 
      37             : #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
      38             : #include "zlib.h"
      39             : #endif
      40             : 
      41             : /* file type markers */
      42             : PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'};
      43             : PHPAPI const char php_sig_psd[4] = {'8', 'B', 'P', 'S'};
      44             : PHPAPI const char php_sig_bmp[2] = {'B', 'M'};
      45             : PHPAPI const char php_sig_swf[3] = {'F', 'W', 'S'};
      46             : PHPAPI const char php_sig_swc[3] = {'C', 'W', 'S'};
      47             : PHPAPI const char php_sig_jpg[3] = {(char) 0xff, (char) 0xd8, (char) 0xff};
      48             : PHPAPI const char php_sig_png[8] = {(char) 0x89, (char) 0x50, (char) 0x4e, (char) 0x47,
      49             :                                     (char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 0x0a};
      50             : PHPAPI const char php_sig_tif_ii[4] = {'I','I', (char)0x2A, (char)0x00};
      51             : PHPAPI const char php_sig_tif_mm[4] = {'M','M', (char)0x00, (char)0x2A};
      52             : PHPAPI const char php_sig_jpc[3]  = {(char)0xff, (char)0x4f, (char)0xff};
      53             : PHPAPI const char php_sig_jp2[12] = {(char)0x00, (char)0x00, (char)0x00, (char)0x0c,
      54             :                                      (char)0x6a, (char)0x50, (char)0x20, (char)0x20,
      55             :                                      (char)0x0d, (char)0x0a, (char)0x87, (char)0x0a};
      56             : PHPAPI const char php_sig_iff[4] = {'F','O','R','M'};
      57             : PHPAPI const char php_sig_ico[4] = {(char)0x00, (char)0x00, (char)0x01, (char)0x00};
      58             : 
      59             : /* REMEMBER TO ADD MIME-TYPE TO FUNCTION php_image_type_to_mime_type */
      60             : /* PCX must check first 64bytes and byte 0=0x0a and byte2 < 0x06 */
      61             : 
      62             : /* return info as a struct, to make expansion easier */
      63             : 
      64             : struct gfxinfo {
      65             :         unsigned int width;
      66             :         unsigned int height;
      67             :         unsigned int bits;
      68             :         unsigned int channels;
      69             : };
      70             : 
      71             : /* {{{ PHP_MINIT_FUNCTION(imagetypes)
      72             :  * Register IMAGETYPE_<xxx> constants used by GetImageSize(), image_type_to_mime_type, ext/exif */
      73       20225 : PHP_MINIT_FUNCTION(imagetypes)
      74             : {
      75       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_GIF",     IMAGE_FILETYPE_GIF,     CONST_CS | CONST_PERSISTENT);
      76       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG",    IMAGE_FILETYPE_JPEG,    CONST_CS | CONST_PERSISTENT);
      77       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_PNG",     IMAGE_FILETYPE_PNG,     CONST_CS | CONST_PERSISTENT);
      78       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_SWF",     IMAGE_FILETYPE_SWF,     CONST_CS | CONST_PERSISTENT);
      79       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_PSD",     IMAGE_FILETYPE_PSD,     CONST_CS | CONST_PERSISTENT);
      80       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_BMP",     IMAGE_FILETYPE_BMP,     CONST_CS | CONST_PERSISTENT);
      81       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_II", IMAGE_FILETYPE_TIFF_II, CONST_CS | CONST_PERSISTENT);
      82       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_MM", IMAGE_FILETYPE_TIFF_MM, CONST_CS | CONST_PERSISTENT);
      83       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_JPC",     IMAGE_FILETYPE_JPC,     CONST_CS | CONST_PERSISTENT);
      84       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_JP2",     IMAGE_FILETYPE_JP2,     CONST_CS | CONST_PERSISTENT);
      85       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_JPX",     IMAGE_FILETYPE_JPX,     CONST_CS | CONST_PERSISTENT);
      86       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_JB2",     IMAGE_FILETYPE_JB2,     CONST_CS | CONST_PERSISTENT);
      87             : #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
      88       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_SWC",     IMAGE_FILETYPE_SWC,     CONST_CS | CONST_PERSISTENT);
      89             : #endif  
      90       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_IFF",     IMAGE_FILETYPE_IFF,     CONST_CS | CONST_PERSISTENT);
      91       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP",    IMAGE_FILETYPE_WBMP,    CONST_CS | CONST_PERSISTENT);
      92       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG2000",IMAGE_FILETYPE_JPC,     CONST_CS | CONST_PERSISTENT); /* keep alias */
      93       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_XBM",     IMAGE_FILETYPE_XBM,     CONST_CS | CONST_PERSISTENT);
      94       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_ICO",     IMAGE_FILETYPE_ICO,     CONST_CS | CONST_PERSISTENT);
      95       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_UNKNOWN", IMAGE_FILETYPE_UNKNOWN, CONST_CS | CONST_PERSISTENT);
      96       20225 :         REGISTER_LONG_CONSTANT("IMAGETYPE_COUNT",   IMAGE_FILETYPE_COUNT,   CONST_CS | CONST_PERSISTENT);
      97       20225 :         return SUCCESS;
      98             : }
      99             : /* }}} */
     100             : 
     101             : /* {{{ php_handle_gif
     102             :  * routine to handle GIF files. If only everything were that easy... ;} */
     103           7 : static struct gfxinfo *php_handle_gif (php_stream * stream TSRMLS_DC)
     104             : {
     105           7 :         struct gfxinfo *result = NULL;
     106             :         unsigned char dim[5];
     107             : 
     108           7 :         if (php_stream_seek(stream, 3, SEEK_CUR))
     109           0 :                 return NULL;
     110             : 
     111           7 :         if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
     112           0 :                 return NULL;
     113             : 
     114           7 :         result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
     115           7 :         result->width    = (unsigned int)dim[0] | (((unsigned int)dim[1])<<8);
     116           7 :         result->height   = (unsigned int)dim[2] | (((unsigned int)dim[3])<<8);
     117           7 :         result->bits     = dim[4]&0x80 ? ((((unsigned int)dim[4])&0x07) + 1) : 0;
     118           7 :         result->channels = 3; /* always */
     119             : 
     120           7 :         return result;
     121             : }
     122             : /* }}} */
     123             : 
     124             : /* {{{ php_handle_psd
     125             :  */
     126           2 : static struct gfxinfo *php_handle_psd (php_stream * stream TSRMLS_DC)
     127             : {
     128           2 :         struct gfxinfo *result = NULL;
     129             :         unsigned char dim[8];
     130             : 
     131           2 :         if (php_stream_seek(stream, 11, SEEK_CUR))
     132           0 :                 return NULL;
     133             : 
     134           2 :         if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
     135           0 :                 return NULL;
     136             : 
     137           2 :         result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
     138           2 :         result->height   =  (((unsigned int)dim[0]) << 24) + (((unsigned int)dim[1]) << 16) + (((unsigned int)dim[2]) << 8) + ((unsigned int)dim[3]);
     139           2 :         result->width    =  (((unsigned int)dim[4]) << 24) + (((unsigned int)dim[5]) << 16) + (((unsigned int)dim[6]) << 8) + ((unsigned int)dim[7]);
     140             : 
     141           2 :         return result;
     142             : }
     143             : /* }}} */
     144             : 
     145             : /* {{{ php_handle_bmp
     146             :  */
     147           7 : static struct gfxinfo *php_handle_bmp (php_stream * stream TSRMLS_DC)
     148             : {
     149           7 :         struct gfxinfo *result = NULL;
     150             :         unsigned char dim[16];
     151             :         int size;
     152             : 
     153           7 :         if (php_stream_seek(stream, 11, SEEK_CUR))
     154           0 :                 return NULL;
     155             : 
     156           7 :         if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
     157           0 :                 return NULL;
     158             : 
     159           7 :         size   = (((unsigned int)dim[ 3]) << 24) + (((unsigned int)dim[ 2]) << 16) + (((unsigned int)dim[ 1]) << 8) + ((unsigned int) dim[ 0]);
     160           7 :         if (size == 12) {
     161           0 :                 result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
     162           0 :                 result->width    =  (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]);
     163           0 :                 result->height   =  (((unsigned int)dim[ 7]) << 8) + ((unsigned int) dim[ 6]);
     164           0 :                 result->bits     =  ((unsigned int)dim[11]);
     165          14 :         } else if (size > 12 && (size <= 64 || size == 108 || size == 124)) {
     166           7 :                 result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
     167           7 :                 result->width    =  (((unsigned int)dim[ 7]) << 24) + (((unsigned int)dim[ 6]) << 16) + (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]);
     168           7 :                 result->height   =  (((unsigned int)dim[11]) << 24) + (((unsigned int)dim[10]) << 16) + (((unsigned int)dim[ 9]) << 8) + ((unsigned int) dim[ 8]);
     169           7 :                 result->height   =  abs((int32_t)result->height);
     170           7 :                 result->bits     =  (((unsigned int)dim[15]) <<  8) +  ((unsigned int)dim[14]);
     171             :         } else {
     172           0 :                 return NULL;
     173             :         }
     174             : 
     175           7 :         return result;
     176             : }
     177             : /* }}} */
     178             : 
     179             : /* {{{ php_swf_get_bits
     180             :  * routines to handle SWF files. */
     181          30 : static unsigned long int php_swf_get_bits (unsigned char* buffer, unsigned int pos, unsigned int count)
     182             : {
     183             :         unsigned int loop;
     184          30 :         unsigned long int result = 0;
     185             : 
     186         412 :         for (loop = pos; loop < pos + count; loop++)
     187             :         {
     188         382 :                 result = result +
     189         382 :                         ((((buffer[loop / 8]) >> (7 - (loop % 8))) & 0x01) << (count - (loop - pos) - 1));
     190             :         }
     191          30 :         return result;
     192             : }
     193             : /* }}} */
     194             : 
     195             : #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
     196             : /* {{{ php_handle_swc
     197             :  */
     198           3 : static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC)
     199             : {
     200           3 :         struct gfxinfo *result = NULL;
     201             : 
     202             :         long bits;
     203             :         unsigned char a[64];
     204           3 :         unsigned long len=64, szlength;
     205           3 :         int factor=1,maxfactor=16;
     206           3 :         int slength, status=0;
     207           3 :         char *b, *buf=NULL, *bufz=NULL;
     208             : 
     209           3 :         b = ecalloc (1, len + 1);
     210             : 
     211           3 :         if (php_stream_seek(stream, 5, SEEK_CUR))
     212           0 :                 return NULL;
     213             : 
     214           3 :         if (php_stream_read(stream, a, sizeof(a)) != sizeof(a))
     215           0 :                 return NULL;
     216             : 
     217           3 :         if (uncompress(b, &len, a, sizeof(a)) != Z_OK) {
     218             :                 /* failed to decompress the file, will try reading the rest of the file */
     219           3 :                 if (php_stream_seek(stream, 8, SEEK_SET))
     220           0 :                         return NULL;
     221             : 
     222           3 :                 slength = php_stream_copy_to_mem(stream, &bufz, PHP_STREAM_COPY_ALL, 0);
     223             :                 
     224             :                 /*
     225             :                  * zlib::uncompress() wants to know the output data length
     226             :                  * if none was given as a parameter
     227             :                  * we try from input length * 2 up to input length * 2^8
     228             :                  * doubling it whenever it wasn't big enough
     229             :                  * that should be eneugh for all real life cases
     230             :                 */
     231             :                 
     232             :                 do {
     233           3 :                         szlength=slength*(1<<factor++);
     234           3 :                         buf = (char *) erealloc(buf,szlength);
     235           3 :                         status = uncompress(buf, &szlength, bufz, slength);
     236           3 :                 } while ((status==Z_BUF_ERROR)&&(factor<maxfactor));
     237             :                 
     238           3 :                 if (bufz) {
     239           3 :                         pefree(bufz, 0);
     240             :                 }       
     241             :                 
     242           3 :                 if (status == Z_OK) {
     243           3 :                          memcpy(b, buf, len);
     244             :                 }
     245             :                 
     246           3 :                 if (buf) { 
     247           3 :                         efree(buf);
     248             :                 }       
     249             :         }
     250             :         
     251           3 :         if (!status) {
     252           3 :                 result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
     253           3 :                 bits = php_swf_get_bits (b, 0, 5);
     254           3 :                 result->width = (php_swf_get_bits (b, 5 + bits, bits) -
     255             :                         php_swf_get_bits (b, 5, bits)) / 20;
     256           3 :                 result->height = (php_swf_get_bits (b, 5 + (3 * bits), bits) -
     257             :                         php_swf_get_bits (b, 5 + (2 * bits), bits)) / 20;
     258             :         } else {
     259           0 :                 result = NULL;
     260             :         }       
     261             :                 
     262           3 :         efree (b);
     263           3 :         return result;
     264             : }
     265             : /* }}} */
     266             : #endif
     267             : 
     268             : /* {{{ php_handle_swf
     269             :  */
     270           3 : static struct gfxinfo *php_handle_swf (php_stream * stream TSRMLS_DC)
     271             : {
     272           3 :         struct gfxinfo *result = NULL;
     273             :         long bits;
     274             :         unsigned char a[32];
     275             : 
     276           3 :         if (php_stream_seek(stream, 5, SEEK_CUR))
     277           0 :                 return NULL;
     278             : 
     279           3 :         if (php_stream_read(stream, a, sizeof(a)) != sizeof(a))
     280           0 :                 return NULL;
     281             : 
     282           3 :         result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
     283           3 :         bits = php_swf_get_bits (a, 0, 5);
     284           3 :         result->width = (php_swf_get_bits (a, 5 + bits, bits) -
     285             :                 php_swf_get_bits (a, 5, bits)) / 20;
     286           3 :         result->height = (php_swf_get_bits (a, 5 + (3 * bits), bits) -
     287             :                 php_swf_get_bits (a, 5 + (2 * bits), bits)) / 20;
     288           3 :         result->bits     = 0;
     289           3 :         result->channels = 0;
     290           3 :         return result;
     291             : }
     292             : /* }}} */
     293             : 
     294             : /* {{{ php_handle_png
     295             :  * routine to handle PNG files */
     296           7 : static struct gfxinfo *php_handle_png (php_stream * stream TSRMLS_DC)
     297             : {
     298           7 :         struct gfxinfo *result = NULL;
     299             :         unsigned char dim[9];
     300             : /* Width:              4 bytes
     301             :  * Height:             4 bytes
     302             :  * Bit depth:          1 byte
     303             :  * Color type:         1 byte
     304             :  * Compression method: 1 byte
     305             :  * Filter method:      1 byte
     306             :  * Interlace method:   1 byte
     307             :  */
     308             : 
     309           7 :         if (php_stream_seek(stream, 8, SEEK_CUR))
     310           0 :                 return NULL;
     311             : 
     312           7 :         if((php_stream_read(stream, dim, sizeof(dim))) < sizeof(dim))
     313           0 :                 return NULL;
     314             : 
     315           7 :         result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
     316           7 :         result->width  = (((unsigned int)dim[0]) << 24) + (((unsigned int)dim[1]) << 16) + (((unsigned int)dim[2]) << 8) + ((unsigned int)dim[3]);
     317           7 :         result->height = (((unsigned int)dim[4]) << 24) + (((unsigned int)dim[5]) << 16) + (((unsigned int)dim[6]) << 8) + ((unsigned int)dim[7]);
     318           7 :         result->bits   = (unsigned int)dim[8];
     319           7 :         return result;
     320             : }
     321             : /* }}} */
     322             : 
     323             : /* routines to handle JPEG data */
     324             : 
     325             : /* some defines for the different JPEG block types */
     326             : #define M_SOF0  0xC0                    /* Start Of Frame N */
     327             : #define M_SOF1  0xC1                    /* N indicates which compression process */
     328             : #define M_SOF2  0xC2                    /* Only SOF0-SOF2 are now in common use */
     329             : #define M_SOF3  0xC3
     330             : #define M_SOF5  0xC5                    /* NB: codes C4 and CC are NOT SOF markers */
     331             : #define M_SOF6  0xC6
     332             : #define M_SOF7  0xC7
     333             : #define M_SOF9  0xC9
     334             : #define M_SOF10 0xCA
     335             : #define M_SOF11 0xCB
     336             : #define M_SOF13 0xCD
     337             : #define M_SOF14 0xCE
     338             : #define M_SOF15 0xCF
     339             : #define M_SOI   0xD8
     340             : #define M_EOI   0xD9                    /* End Of Image (end of datastream) */
     341             : #define M_SOS   0xDA                    /* Start Of Scan (begins compressed data) */
     342             : #define M_APP0  0xe0
     343             : #define M_APP1  0xe1
     344             : #define M_APP2  0xe2
     345             : #define M_APP3  0xe3
     346             : #define M_APP4  0xe4
     347             : #define M_APP5  0xe5
     348             : #define M_APP6  0xe6
     349             : #define M_APP7  0xe7
     350             : #define M_APP8  0xe8
     351             : #define M_APP9  0xe9
     352             : #define M_APP10 0xea
     353             : #define M_APP11 0xeb
     354             : #define M_APP12 0xec
     355             : #define M_APP13 0xed
     356             : #define M_APP14 0xee
     357             : #define M_APP15 0xef
     358             : #define M_COM   0xFE            /* COMment                                  */
     359             : 
     360             : #define M_PSEUDO 0xFFD8                 /* pseudo marker for start of image(byte 0) */
     361             : 
     362             : /* {{{ php_read2
     363             :  */
     364         228 : static unsigned short php_read2(php_stream * stream TSRMLS_DC)
     365             : {
     366             :         unsigned char a[2];
     367             : 
     368             :         /* just return 0 if we hit the end-of-file */
     369         228 :         if((php_stream_read(stream, a, sizeof(a))) <= 0) return 0;
     370             : 
     371         228 :         return (((unsigned short)a[0]) << 8) + ((unsigned short)a[1]);
     372             : }
     373             : /* }}} */
     374             : 
     375             : /* {{{ php_next_marker
     376             :  * get next marker byte from file */
     377         177 : static unsigned int php_next_marker(php_stream * stream, int last_marker, int comment_correction, int ff_read TSRMLS_DC)
     378             : {
     379         177 :         int a=0, marker;
     380             : 
     381             :         /* get marker byte, swallowing possible padding                           */
     382         179 :         if (last_marker==M_COM && comment_correction) {
     383             :                 /* some software does not count the length bytes of COM section           */
     384             :                 /* one company doing so is very much envolved in JPEG... so we accept too */
     385             :                 /* by the way: some of those companies changed their code now...          */
     386           2 :                 comment_correction = 2;
     387             :         } else {
     388         175 :                 last_marker = 0;
     389         175 :                 comment_correction = 0;
     390             :         }
     391         177 :         if (ff_read) {
     392          30 :                 a = 1; /* already read 0xff in filetype detection */
     393             :         }
     394             :         do {
     395         326 :                 if ((marker = php_stream_getc(stream)) == EOF)
     396             :                 {
     397           0 :                         return M_EOI;/* we hit EOF */
     398             :                 }
     399         326 :                 if (last_marker==M_COM && comment_correction>0)
     400             :                 {
     401           3 :                         if (marker != 0xFF)
     402             :                         {
     403           2 :                                 marker = 0xff;
     404           2 :                                 comment_correction--;
     405             :                         } else {
     406           1 :                                 last_marker = M_PSEUDO; /* stop skipping non 0xff for M_COM */
     407             :                         }
     408             :                 }
     409         326 :                 a++;
     410         326 :         } while (marker == 0xff);
     411         177 :         if (a < 2)
     412             :         {
     413           0 :                 return M_EOI; /* at least one 0xff is needed before marker code */
     414             :         }
     415         177 :         if ( last_marker==M_COM && comment_correction)
     416             :         {
     417           0 :                 return M_EOI; /* ah illegal: char after COM section not 0xFF */
     418             :         }
     419         177 :         return (unsigned int)marker;
     420             : }
     421             : /* }}} */
     422             : 
     423             : /* {{{ php_skip_variable
     424             :  * skip over a variable-length block; assumes proper length marker */
     425          91 : static int php_skip_variable(php_stream * stream TSRMLS_DC)
     426             : {
     427          91 :         off_t length = ((unsigned int)php_read2(stream TSRMLS_CC));
     428             : 
     429          91 :         if (length < 2)      {
     430           0 :                 return 0;
     431             :         }
     432          91 :         length = length - 2;
     433          91 :         php_stream_seek(stream, (long)length, SEEK_CUR);
     434          91 :         return 1;
     435             : }
     436             : /* }}} */
     437             : 
     438             : /* {{{ php_read_APP
     439             :  */
     440          29 : static int php_read_APP(php_stream * stream, unsigned int marker, zval *info TSRMLS_DC)
     441             : {
     442             :         unsigned short length;
     443             :         unsigned char *buffer;
     444             :         unsigned char markername[16];
     445             :         zval *tmp;
     446             : 
     447          29 :         length = php_read2(stream TSRMLS_CC);
     448          29 :         if (length < 2)      {
     449           0 :                 return 0;
     450             :         }
     451          29 :         length -= 2;                            /* length includes itself */
     452             : 
     453          29 :         buffer = emalloc(length);
     454             : 
     455          29 :         if (php_stream_read(stream, buffer, (long) length) <= 0) {
     456           0 :                 efree(buffer);
     457           0 :                 return 0;
     458             :         }
     459             : 
     460          29 :         snprintf(markername, sizeof(markername), "APP%d", marker - M_APP0);
     461             : 
     462          29 :         if (zend_hash_find(Z_ARRVAL_P(info), markername, strlen(markername)+1, (void **) &tmp) == FAILURE) {
     463             :                 /* XXX we onyl catch the 1st tag of it's kind! */
     464          29 :                 add_assoc_stringl(info, markername, buffer, length, 1);
     465             :         }
     466             : 
     467          29 :         efree(buffer);
     468          29 :         return 1;
     469             : }
     470             : /* }}} */
     471             : 
     472             : /* {{{ php_handle_jpeg
     473             :    main loop to parse JPEG structure */
     474          30 : static struct gfxinfo *php_handle_jpeg (php_stream * stream, zval *info TSRMLS_DC) 
     475             : {
     476          30 :         struct gfxinfo *result = NULL;
     477          30 :         unsigned int marker = M_PSEUDO;
     478          30 :         unsigned short length, ff_read=1;
     479             : 
     480             :         for (;;) {
     481         177 :                 marker = php_next_marker(stream, marker, 1, ff_read TSRMLS_CC);
     482         177 :                 ff_read = 0;
     483         177 :                 switch (marker) {
     484             :                         case M_SOF0:
     485             :                         case M_SOF1:
     486             :                         case M_SOF2:
     487             :                         case M_SOF3:
     488             :                         case M_SOF5:
     489             :                         case M_SOF6:
     490             :                         case M_SOF7:
     491             :                         case M_SOF9:
     492             :                         case M_SOF10:
     493             :                         case M_SOF11:
     494             :                         case M_SOF13:
     495             :                         case M_SOF14:
     496             :                         case M_SOF15:
     497          30 :                                 if (result == NULL) {
     498             :                                         /* handle SOFn block */
     499          30 :                                         result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
     500          30 :                                         length = php_read2(stream TSRMLS_CC);
     501          30 :                                         result->bits     = php_stream_getc(stream);
     502          30 :                                         result->height   = php_read2(stream TSRMLS_CC);
     503          30 :                                         result->width    = php_read2(stream TSRMLS_CC);
     504          30 :                                         result->channels = php_stream_getc(stream);
     505          30 :                                         if (!info || length < 8) { /* if we don't want an extanded info -> return */
     506           3 :                                                 return result;
     507             :                                         }
     508          27 :                                         if (php_stream_seek(stream, length - 8, SEEK_CUR)) { /* file error after info */
     509           0 :                                                 return result;
     510             :                                         }
     511             :                                 } else {
     512           0 :                                         if (!php_skip_variable(stream TSRMLS_CC)) {
     513           0 :                                                 return result;
     514             :                                         }
     515             :                                 }
     516          27 :                                 break;
     517             : 
     518             :                         case M_APP0:
     519             :                         case M_APP1:
     520             :                         case M_APP2:
     521             :                         case M_APP3:
     522             :                         case M_APP4:
     523             :                         case M_APP5:
     524             :                         case M_APP6:
     525             :                         case M_APP7:
     526             :                         case M_APP8:
     527             :                         case M_APP9:
     528             :                         case M_APP10:
     529             :                         case M_APP11:
     530             :                         case M_APP12:
     531             :                         case M_APP13:
     532             :                         case M_APP14:
     533             :                         case M_APP15:
     534          32 :                                 if (info) {
     535          29 :                                         if (!php_read_APP(stream, marker, info TSRMLS_CC)) { /* read all the app markes... */
     536           0 :                                                 return result;
     537             :                                         }
     538             :                                 } else {
     539           3 :                                         if (!php_skip_variable(stream TSRMLS_CC)) {
     540           0 :                                                 return result;
     541             :                                         }
     542             :                                 }
     543          32 :                                 break;
     544             : 
     545             :                         case M_SOS:
     546             :                         case M_EOI:
     547          27 :                                 return result;  /* we're about to hit image data, or are at EOF. stop processing. */
     548             :                         
     549             :                         default:
     550          88 :                                 if (!php_skip_variable(stream TSRMLS_CC)) { /* anything else isn't interesting */
     551           0 :                                         return result;
     552             :                                 }
     553             :                                 break;
     554             :                 }
     555         147 :         }
     556             : 
     557             :         return result; /* perhaps image broken -> no info but size */
     558             : }
     559             : /* }}} */
     560             : 
     561             : /* {{{ php_read4
     562             :  */
     563          21 : static unsigned int php_read4(php_stream * stream TSRMLS_DC)
     564             : {
     565             :         unsigned char a[4];
     566             : 
     567             :         /* just return 0 if we hit the end-of-file */
     568          21 :         if ((php_stream_read(stream, a, sizeof(a))) != sizeof(a)) return 0;
     569             : 
     570          42 :         return (((unsigned int)a[0]) << 24)
     571          21 :              + (((unsigned int)a[1]) << 16)
     572          21 :              + (((unsigned int)a[2]) <<  8)
     573          21 :              + (((unsigned int)a[3]));
     574             : }
     575             : /* }}} */
     576             : 
     577             : /* {{{ JPEG 2000 Marker Codes */
     578             : #define JPEG2000_MARKER_PREFIX 0xFF /* All marker codes start with this */
     579             : #define JPEG2000_MARKER_SOC 0x4F /* Start of Codestream */
     580             : #define JPEG2000_MARKER_SOT 0x90 /* Start of Tile part */
     581             : #define JPEG2000_MARKER_SOD 0x93 /* Start of Data */
     582             : #define JPEG2000_MARKER_EOC 0xD9 /* End of Codestream */
     583             : #define JPEG2000_MARKER_SIZ 0x51 /* Image and tile size */
     584             : #define JPEG2000_MARKER_COD 0x52 /* Coding style default */ 
     585             : #define JPEG2000_MARKER_COC 0x53 /* Coding style component */
     586             : #define JPEG2000_MARKER_RGN 0x5E /* Region of interest */
     587             : #define JPEG2000_MARKER_QCD 0x5C /* Quantization default */
     588             : #define JPEG2000_MARKER_QCC 0x5D /* Quantization component */
     589             : #define JPEG2000_MARKER_POC 0x5F /* Progression order change */
     590             : #define JPEG2000_MARKER_TLM 0x55 /* Tile-part lengths */
     591             : #define JPEG2000_MARKER_PLM 0x57 /* Packet length, main header */
     592             : #define JPEG2000_MARKER_PLT 0x58 /* Packet length, tile-part header */
     593             : #define JPEG2000_MARKER_PPM 0x60 /* Packed packet headers, main header */
     594             : #define JPEG2000_MARKER_PPT 0x61 /* Packed packet headers, tile part header */
     595             : #define JPEG2000_MARKER_SOP 0x91 /* Start of packet */
     596             : #define JPEG2000_MARKER_EPH 0x92 /* End of packet header */
     597             : #define JPEG2000_MARKER_CRG 0x63 /* Component registration */
     598             : #define JPEG2000_MARKER_COM 0x64 /* Comment */
     599             : /* }}} */
     600             : 
     601             : /* {{{ php_handle_jpc
     602             :    Main loop to parse JPEG2000 raw codestream structure */
     603           6 : static struct gfxinfo *php_handle_jpc(php_stream * stream TSRMLS_DC)
     604             : {
     605           6 :         struct gfxinfo *result = NULL;
     606             :         unsigned short dummy_short;
     607             :         int highest_bit_depth, bit_depth;
     608             :         unsigned char first_marker_id;
     609             :         unsigned int i;
     610             : 
     611             :         /* JPEG 2000 components can be vastly different from one another.
     612             :            Each component can be sampled at a different resolution, use
     613             :            a different colour space, have a separate colour depth, and
     614             :            be compressed totally differently! This makes giving a single
     615             :            "bit depth" answer somewhat problematic. For this implementation
     616             :            we'll use the highest depth encountered. */
     617             : 
     618             :         /* Get the single byte that remains after the file type indentification */
     619           6 :         first_marker_id = php_stream_getc(stream);
     620             : 
     621             :         /* Ensure that this marker is SIZ (as is mandated by the standard) */
     622           6 :         if (first_marker_id != JPEG2000_MARKER_SIZ) {
     623           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "JPEG2000 codestream corrupt(Expected SIZ marker not found after SOC)");
     624           0 :                 return NULL;
     625             :         }
     626             : 
     627           6 :         result = (struct gfxinfo *)ecalloc(1, sizeof(struct gfxinfo));
     628             : 
     629           6 :         dummy_short = php_read2(stream TSRMLS_CC); /* Lsiz */
     630           6 :         dummy_short = php_read2(stream TSRMLS_CC); /* Rsiz */
     631           6 :         result->width = php_read4(stream TSRMLS_CC); /* Xsiz */
     632           6 :         result->height = php_read4(stream TSRMLS_CC); /* Ysiz */
     633             : 
     634             : #if MBO_0
     635             :         php_read4(stream TSRMLS_CC); /* XOsiz */
     636             :         php_read4(stream TSRMLS_CC); /* YOsiz */
     637             :         php_read4(stream TSRMLS_CC); /* XTsiz */
     638             :         php_read4(stream TSRMLS_CC); /* YTsiz */
     639             :         php_read4(stream TSRMLS_CC); /* XTOsiz */
     640             :         php_read4(stream TSRMLS_CC); /* YTOsiz */
     641             : #else
     642           6 :         if (php_stream_seek(stream, 24, SEEK_CUR)) {
     643           0 :                 efree(result);
     644           0 :                 return NULL;
     645             :         }
     646             : #endif
     647             : 
     648           6 :         result->channels = php_read2(stream TSRMLS_CC); /* Csiz */
     649           6 :         if (result->channels < 0 || result->channels > 256) {
     650           0 :                 efree(result);
     651           0 :                 return NULL;
     652             :         }
     653             : 
     654             :         /* Collect bit depth info */
     655           6 :         highest_bit_depth = 0;
     656          24 :         for (i = 0; i < result->channels; i++) {
     657          18 :                 bit_depth = php_stream_getc(stream); /* Ssiz[i] */
     658          18 :                 bit_depth++;
     659          18 :                 if (bit_depth > highest_bit_depth) {
     660           6 :                         highest_bit_depth = bit_depth;
     661             :                 }
     662             : 
     663          18 :                 php_stream_getc(stream); /* XRsiz[i] */
     664          18 :                 php_stream_getc(stream); /* YRsiz[i] */
     665             :         }
     666             : 
     667           6 :         result->bits = highest_bit_depth;
     668             : 
     669           6 :         return result;
     670             : }
     671             : /* }}} */
     672             : 
     673             : /* {{{ php_handle_jp2
     674             :    main loop to parse JPEG 2000 JP2 wrapper format structure */
     675           3 : static struct gfxinfo *php_handle_jp2(php_stream *stream TSRMLS_DC)
     676             : {
     677           3 :         struct gfxinfo *result = NULL;
     678             :         unsigned int box_length;
     679             :         unsigned int box_type;
     680           3 :         char jp2c_box_id[] = {(char)0x6a, (char)0x70, (char)0x32, (char)0x63};
     681             : 
     682             :         /* JP2 is a wrapper format for JPEG 2000. Data is contained within "boxes".
     683             :            Boxes themselves can be contained within "super-boxes". Super-Boxes can
     684             :            contain super-boxes which provides us with a hierarchical storage system.
     685             : 
     686             :            It is valid for a JP2 file to contain multiple individual codestreams.
     687             :            We'll just look for the first codestream at the root of the box structure
     688             :            and handle that.
     689             :         */
     690             : 
     691             :         for (;;)
     692             :         {
     693           9 :                 box_length = php_read4(stream TSRMLS_CC); /* LBox */
     694             :                 /* TBox */
     695           9 :                 if (php_stream_read(stream, (void *)&box_type, sizeof(box_type)) != sizeof(box_type)) {
     696             :                         /* Use this as a general "out of stream" error */
     697           0 :                         break;
     698             :                 }
     699             : 
     700           9 :                 if (box_length == 1) {
     701             :                         /* We won't handle XLBoxes */
     702           0 :                         return NULL;
     703             :                 }
     704             : 
     705           9 :                 if (!memcmp(&box_type, jp2c_box_id, 4))
     706             :                 {
     707             :                         /* Skip the first 3 bytes to emulate the file type examination */
     708           3 :                         php_stream_seek(stream, 3, SEEK_CUR);
     709             : 
     710           3 :                         result = php_handle_jpc(stream TSRMLS_CC);
     711           3 :                         break;
     712             :                 }
     713             : 
     714             :                 /* Stop if this was the last box */
     715           6 :                 if ((int)box_length <= 0) {
     716           0 :                         break;
     717             :                 }
     718             : 
     719             :                 /* Skip over LBox (Which includes both TBox and LBox itself */
     720           6 :                 if (php_stream_seek(stream, box_length - 8, SEEK_CUR)) {
     721           0 :                         break;
     722             :                 }
     723           6 :         }
     724             : 
     725           3 :         if (result == NULL) {
     726           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "JP2 file has no codestreams at root level");
     727             :         }
     728             : 
     729           3 :         return result;
     730             : }
     731             : /* }}} */
     732             : 
     733             : /* {{{ tiff constants
     734             :  */
     735             : PHPAPI const int php_tiff_bytes_per_format[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
     736             : 
     737             : /* uncompressed only */
     738             : #define TAG_IMAGEWIDTH              0x0100
     739             : #define TAG_IMAGEHEIGHT             0x0101
     740             : /* compressed images only */
     741             : #define TAG_COMP_IMAGEWIDTH         0xA002
     742             : #define TAG_COMP_IMAGEHEIGHT        0xA003
     743             : 
     744             : #define TAG_FMT_BYTE       1
     745             : #define TAG_FMT_STRING     2
     746             : #define TAG_FMT_USHORT     3
     747             : #define TAG_FMT_ULONG      4
     748             : #define TAG_FMT_URATIONAL  5
     749             : #define TAG_FMT_SBYTE      6
     750             : #define TAG_FMT_UNDEFINED  7
     751             : #define TAG_FMT_SSHORT     8
     752             : #define TAG_FMT_SLONG      9
     753             : #define TAG_FMT_SRATIONAL 10
     754             : #define TAG_FMT_SINGLE    11
     755             : #define TAG_FMT_DOUBLE    12
     756             : /* }}} */
     757             : 
     758             : /* {{{ php_ifd_get16u
     759             :  * Convert a 16 bit unsigned value from file's native byte order */
     760         150 : static int php_ifd_get16u(void *Short, int motorola_intel)
     761             : {
     762         150 :         if (motorola_intel) {
     763          30 :                 return (((unsigned char *)Short)[0] << 8) | ((unsigned char *)Short)[1];
     764             :         } else {
     765         120 :                 return (((unsigned char *)Short)[1] << 8) | ((unsigned char *)Short)[0];
     766             :         }
     767             : }
     768             : /* }}} */
     769             : 
     770             : /* {{{ php_ifd_get16s
     771             :  * Convert a 16 bit signed value from file's native byte order */
     772           6 : static signed short php_ifd_get16s(void *Short, int motorola_intel)
     773             : {
     774           6 :         return (signed short)php_ifd_get16u(Short, motorola_intel);
     775             : }
     776             : /* }}} */
     777             : 
     778             : /* {{{ php_ifd_get32s
     779             :  * Convert a 32 bit signed value from file's native byte order */
     780          23 : static int php_ifd_get32s(void *Long, int motorola_intel)
     781             : {
     782          23 :         if (motorola_intel) {
     783          16 :                 return  ((( char *)Long)[0] << 24) | (((unsigned char *)Long)[1] << 16)
     784           8 :                       | (((unsigned char *)Long)[2] << 8 ) | (((unsigned char *)Long)[3] << 0 );
     785             :         } else {
     786          30 :                 return  ((( char *)Long)[3] << 24) | (((unsigned char *)Long)[2] << 16)
     787          15 :                       | (((unsigned char *)Long)[1] << 8 ) | (((unsigned char *)Long)[0] << 0 );
     788             :         }
     789             : }
     790             : /* }}} */
     791             : 
     792             : /* {{{ php_ifd_get32u
     793             :  * Convert a 32 bit unsigned value from file's native byte order */
     794          17 : static unsigned php_ifd_get32u(void *Long, int motorola_intel)
     795             : {
     796          17 :         return (unsigned)php_ifd_get32s(Long, motorola_intel) & 0xffffffff;
     797             : }
     798             : /* }}} */
     799             : 
     800             : /* {{{ php_handle_tiff
     801             :    main loop to parse TIFF structure */
     802           4 : static struct gfxinfo *php_handle_tiff (php_stream * stream, zval *info, int motorola_intel TSRMLS_DC)
     803             : {
     804           4 :         struct gfxinfo *result = NULL;
     805             :         int i, num_entries;
     806             :         unsigned char *dir_entry;
     807           4 :         size_t ifd_size, dir_size, entry_value, width=0, height=0, ifd_addr;
     808             :         int entry_tag , entry_type;
     809             :         char *ifd_data, ifd_ptr[4];
     810             : 
     811           4 :         if (php_stream_read(stream, ifd_ptr, 4) != 4)
     812           0 :                 return NULL;
     813           4 :         ifd_addr = php_ifd_get32u(ifd_ptr, motorola_intel);
     814           4 :         if (php_stream_seek(stream, ifd_addr-8, SEEK_CUR))
     815           0 :                 return NULL;
     816           4 :         ifd_size = 2;
     817           4 :         ifd_data = emalloc(ifd_size);
     818           4 :         if (php_stream_read(stream, ifd_data, 2) != 2) {
     819           0 :                 efree(ifd_data);
     820           0 :                 return NULL;
     821             :         }
     822           4 :         num_entries = php_ifd_get16u(ifd_data, motorola_intel);
     823           4 :         dir_size = 2/*num dir entries*/ +12/*length of entry*/*num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;
     824           4 :         ifd_size = dir_size;
     825           4 :         ifd_data = erealloc(ifd_data,ifd_size);
     826           4 :         if (php_stream_read(stream, ifd_data+2, dir_size-2) != dir_size-2) {
     827           0 :                 efree(ifd_data);
     828           0 :                 return NULL;
     829             :         }
     830             :         /* now we have the directory we can look how long it should be */
     831           4 :         ifd_size = dir_size;
     832          57 :         for(i=0;i<num_entries;i++) {
     833          53 :                 dir_entry        = ifd_data+2+i*12;
     834          53 :                 entry_tag    = php_ifd_get16u(dir_entry+0, motorola_intel);
     835          53 :                 entry_type   = php_ifd_get16u(dir_entry+2, motorola_intel);
     836          53 :                 switch(entry_type) {
     837             :                         case TAG_FMT_BYTE:
     838             :                         case TAG_FMT_SBYTE:
     839           0 :                                 entry_value  = (size_t)(dir_entry[8]);
     840           0 :                                 break;
     841             :                         case TAG_FMT_USHORT:
     842          34 :                                 entry_value  = php_ifd_get16u(dir_entry+8, motorola_intel);
     843          34 :                                 break;
     844             :                         case TAG_FMT_SSHORT:
     845           0 :                                 entry_value  = php_ifd_get16s(dir_entry+8, motorola_intel);
     846           0 :                                 break;
     847             :                         case TAG_FMT_ULONG:
     848          13 :                                 entry_value  = php_ifd_get32u(dir_entry+8, motorola_intel);
     849          13 :                                 break;
     850             :                         case TAG_FMT_SLONG:
     851           0 :                                 entry_value  = php_ifd_get32s(dir_entry+8, motorola_intel);
     852           0 :                                 break;
     853             :                         default:
     854           6 :                                 continue;
     855             :                 }
     856          47 :                 switch(entry_tag) {
     857             :                         case TAG_IMAGEWIDTH:
     858             :                         case TAG_COMP_IMAGEWIDTH:
     859           4 :                                 width  = entry_value;
     860           4 :                                 break;
     861             :                         case TAG_IMAGEHEIGHT:
     862             :                         case TAG_COMP_IMAGEHEIGHT:
     863           4 :                                 height = entry_value;
     864             :                                 break;
     865             :                 }
     866             :         }
     867           4 :         efree(ifd_data);
     868           4 :         if ( width && height) {
     869             :                 /* not the same when in for-loop */
     870           4 :                 result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
     871           4 :                 result->height   = height;
     872           4 :                 result->width    = width;
     873           4 :                 result->bits     = 0;
     874           4 :                 result->channels = 0;
     875           4 :                 return result;
     876             :         }
     877           0 :         return NULL;
     878             : }
     879             : /* }}} */
     880             : 
     881             : /* {{{ php_handle_psd
     882             :  */
     883           3 : static struct gfxinfo *php_handle_iff(php_stream * stream TSRMLS_DC)
     884             : {
     885             :         struct gfxinfo * result;
     886             :         unsigned char a[10];
     887             :         int chunkId;
     888             :         int size;
     889             :         short width, height, bits;
     890             : 
     891           3 :         if (php_stream_read(stream, a, 8) != 8) {
     892           0 :                 return NULL;
     893             :         }
     894           3 :         if (strncmp(a+4, "ILBM", 4) && strncmp(a+4, "PBM ", 4)) {
     895           0 :                 return NULL;
     896             :         }
     897             : 
     898             :         /* loop chunks to find BMHD chunk */
     899             :         do {
     900           3 :                 if (php_stream_read(stream, a, 8) != 8) {
     901           0 :                         return NULL;
     902             :                 }
     903           3 :                 chunkId = php_ifd_get32s(a+0, 1);
     904           3 :                 size    = php_ifd_get32s(a+4, 1);
     905           3 :                 if (size < 0) {
     906           0 :                         return NULL;
     907             :                 }
     908           3 :                 if ((size & 1) == 1) {
     909           0 :                         size++;
     910             :                 }
     911           3 :                 if (chunkId == 0x424d4844) { /* BMHD chunk */
     912           3 :                         if (size < 9 || php_stream_read(stream, a, 9) != 9) {
     913           0 :                                 return NULL;
     914             :                         }
     915           3 :                         width  = php_ifd_get16s(a+0, 1);
     916           3 :                         height = php_ifd_get16s(a+2, 1);
     917           3 :                         bits   = a[8] & 0xff;
     918           3 :                         if (width > 0 && height > 0 && bits > 0 && bits < 33) {
     919           3 :                                 result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
     920           3 :                                 result->width    = width;
     921           3 :                                 result->height   = height;
     922           3 :                                 result->bits     = bits;
     923           3 :                                 result->channels = 0;
     924           3 :                                 return result;
     925             :                         }
     926             :                 } else {
     927           0 :                         if (php_stream_seek(stream, size, SEEK_CUR)) {
     928           0 :                                 return NULL;
     929             :                         }
     930             :                 }
     931           0 :         } while (1);
     932             : }
     933             : /* }}} */
     934             : 
     935             : /* {{{ php_get_wbmp
     936             :  * int WBMP file format type
     937             :  * byte Header Type
     938             :  *      byte Extended Header
     939             :  *              byte Header Data (type 00 = multibyte)
     940             :  *              byte Header Data (type 11 = name/pairs)
     941             :  * int Number of columns
     942             :  * int Number of rows
     943             :  */
     944          11 : static int php_get_wbmp(php_stream *stream, struct gfxinfo **result, int check TSRMLS_DC)
     945             : {
     946          11 :         int i, width = 0, height = 0;
     947             : 
     948          11 :         if (php_stream_rewind(stream)) {
     949           0 :                 return 0;
     950             :         }
     951             : 
     952             :         /* get type */
     953          11 :         if (php_stream_getc(stream) != 0) {
     954           9 :                 return 0;
     955             :         }
     956             : 
     957             :         /* skip header */
     958             :         do {
     959           2 :                 i = php_stream_getc(stream);
     960           2 :                 if (i < 0) {
     961           0 :                         return 0;
     962             :                 }
     963           2 :         } while (i & 0x80);
     964             : 
     965             :         /* get width */
     966             :         do {
     967           2 :                 i = php_stream_getc(stream);
     968           2 :                 if (i < 0) {
     969           0 :                         return 0;
     970             :                 }
     971           2 :                 width = (width << 7) | (i & 0x7f);
     972           2 :         } while (i & 0x80);
     973             :         
     974             :         /* get height */
     975             :         do {
     976           2 :                 i = php_stream_getc(stream);
     977           2 :                 if (i < 0) {
     978           0 :                         return 0;
     979             :                 }
     980           2 :                 height = (height << 7) | (i & 0x7f);
     981           2 :         } while (i & 0x80);
     982             : 
     983             :         /* maximum valid sizes for wbmp (although 127x127 may be a more accurate one) */
     984           2 :         if (!height || !width || height > 2048 || width > 2048) {
     985           0 :                 return 0;
     986             :         }
     987             :         
     988           2 :         if (!check) {
     989           1 :                 (*result)->width = width;
     990           1 :                 (*result)->height = height;
     991             :         }
     992             : 
     993           2 :         return IMAGE_FILETYPE_WBMP;
     994             : }
     995             : /* }}} */
     996             : 
     997             : /* {{{ php_handle_wbmp
     998             : */
     999           1 : static struct gfxinfo *php_handle_wbmp(php_stream * stream TSRMLS_DC)
    1000             : {
    1001           1 :         struct gfxinfo *result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
    1002             : 
    1003           1 :         if (!php_get_wbmp(stream, &result, 0 TSRMLS_CC)) {
    1004           0 :                 efree(result);
    1005           0 :                 return NULL;
    1006             :         }
    1007             : 
    1008           1 :         return result;
    1009             : }
    1010             : /* }}} */
    1011             : 
    1012             : /* {{{ php_get_xbm
    1013             :  */
    1014          10 : static int php_get_xbm(php_stream *stream, struct gfxinfo **result TSRMLS_DC)
    1015             : {
    1016             :     char *fline;
    1017             :     char *iname;
    1018             :     char *type;
    1019             :     int value;
    1020          10 :     unsigned int width = 0, height = 0;
    1021             : 
    1022          10 :         if (result) {
    1023           1 :                 *result = NULL;
    1024             :         }
    1025          10 :         if (php_stream_rewind(stream)) {
    1026           0 :                 return 0;
    1027             :         }
    1028          30 :         while ((fline=php_stream_gets(stream, NULL, 0)) != NULL) {
    1029          12 :                 iname = estrdup(fline); /* simple way to get necessary buffer of required size */
    1030          12 :                 if (sscanf(fline, "#define %s %d", iname, &value) == 2) {
    1031           4 :                         if (!(type = strrchr(iname, '_'))) {
    1032           0 :                                 type = iname;
    1033             :                         } else {
    1034           4 :                                 type++;
    1035             :                         }
    1036             :         
    1037           4 :                         if (!strcmp("width", type)) {
    1038           2 :                                 width = (unsigned int) value;
    1039           2 :                                 if (height) {
    1040           0 :                                         efree(iname);
    1041           0 :                                         break;
    1042             :                                 }
    1043             :                         }
    1044           4 :                         if (!strcmp("height", type)) {
    1045           2 :                                 height = (unsigned int) value;
    1046           2 :                                 if (width) {
    1047           2 :                                         efree(iname);
    1048           2 :                                         break;
    1049             :                                 }
    1050             :                         }
    1051             :                 }
    1052          10 :                 efree(fline);
    1053          10 :                 efree(iname);
    1054             :         }
    1055          10 :         if (fline) {
    1056           2 :                 efree(fline);
    1057             :         }
    1058             : 
    1059          10 :         if (width && height) {
    1060           2 :                 if (result) {
    1061           1 :                         *result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
    1062           1 :                         (*result)->width = width;
    1063           1 :                         (*result)->height = height;
    1064             :                 }
    1065           2 :                 return IMAGE_FILETYPE_XBM;
    1066             :         }
    1067             : 
    1068           8 :         return 0;
    1069             : }
    1070             : /* }}} */
    1071             : 
    1072             : /* {{{ php_handle_xbm
    1073             :  */
    1074           1 : static struct gfxinfo *php_handle_xbm(php_stream * stream TSRMLS_DC)
    1075             : {
    1076             :         struct gfxinfo *result;
    1077           1 :         php_get_xbm(stream, &result TSRMLS_CC);
    1078           1 :         return result;
    1079             : }
    1080             : /* }}} */
    1081             : 
    1082             : /* {{{ php_handle_ico
    1083             :  */
    1084           0 : static struct gfxinfo *php_handle_ico(php_stream * stream TSRMLS_DC)
    1085             : {
    1086           0 :         struct gfxinfo *result = NULL;
    1087             :         unsigned char dim[16];
    1088           0 :         int num_icons = 0;
    1089             : 
    1090           0 :         if (php_stream_read(stream, dim, 2) != 2)
    1091           0 :                 return NULL;
    1092             : 
    1093           0 :         num_icons = (((unsigned int)dim[1]) << 8) + ((unsigned int) dim[0]);
    1094             : 
    1095           0 :         if (num_icons < 1 || num_icons > 255)
    1096           0 :                 return NULL;
    1097             : 
    1098           0 :         result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
    1099             : 
    1100           0 :         while (num_icons > 0)
    1101             :         {
    1102           0 :                 if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
    1103           0 :                         break;
    1104             : 
    1105           0 :                 if ((((unsigned int)dim[7]) <<  8) +  ((unsigned int)dim[6]) >= result->bits)
    1106             :                 {
    1107           0 :                         result->width    =  (unsigned int)dim[0];
    1108           0 :                         result->height   =  (unsigned int)dim[1];
    1109           0 :                         result->bits     =  (((unsigned int)dim[7]) <<  8) +  ((unsigned int)dim[6]);
    1110             :                 }
    1111           0 :                 num_icons--;
    1112             :         }
    1113             : 
    1114           0 :         return result;
    1115             : }
    1116             : /* }}} */
    1117             : 
    1118             : /* {{{ php_image_type_to_mime_type
    1119             :  * Convert internal image_type to mime type */
    1120         185 : PHPAPI char * php_image_type_to_mime_type(int image_type)
    1121             : {
    1122         185 :         switch( image_type) {
    1123             :                 case IMAGE_FILETYPE_GIF:
    1124          15 :                         return "image/gif";
    1125             :                 case IMAGE_FILETYPE_JPEG:
    1126          61 :                         return "image/jpeg";
    1127             :                 case IMAGE_FILETYPE_PNG:
    1128          10 :                         return "image/png";
    1129             :                 case IMAGE_FILETYPE_SWF:
    1130             :                 case IMAGE_FILETYPE_SWC:
    1131          11 :                         return "application/x-shockwave-flash";
    1132             :                 case IMAGE_FILETYPE_PSD:
    1133           5 :                         return "image/psd";
    1134             :                 case IMAGE_FILETYPE_BMP:
    1135          12 :                         return "image/x-ms-bmp";
    1136             :                 case IMAGE_FILETYPE_TIFF_II:
    1137             :                 case IMAGE_FILETYPE_TIFF_MM:
    1138          19 :                         return "image/tiff";
    1139             :                 case IMAGE_FILETYPE_IFF:
    1140           6 :                         return "image/iff";
    1141             :                 case IMAGE_FILETYPE_WBMP:
    1142           3 :                         return "image/vnd.wap.wbmp";
    1143             :                 case IMAGE_FILETYPE_JPC:
    1144           7 :                         return "application/octet-stream";
    1145             :                 case IMAGE_FILETYPE_JP2:
    1146           6 :                         return "image/jp2";
    1147             :                 case IMAGE_FILETYPE_XBM:
    1148           3 :                         return "image/xbm";
    1149             :                 case IMAGE_FILETYPE_ICO:
    1150           2 :                         return "image/vnd.microsoft.icon";
    1151             :                 default:
    1152             :                 case IMAGE_FILETYPE_UNKNOWN:
    1153          25 :                         return "application/octet-stream"; /* suppose binary format */
    1154             :         }
    1155             : }
    1156             : /* }}} */
    1157             : 
    1158             : /* {{{ proto string image_type_to_mime_type(int imagetype)
    1159             :    Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */
    1160          84 : PHP_FUNCTION(image_type_to_mime_type)
    1161             : {
    1162             :         long p_image_type;
    1163             : 
    1164          84 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &p_image_type) == FAILURE) {
    1165           9 :                 return;
    1166             :         }
    1167             : 
    1168          75 :         ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(p_image_type), 1);
    1169             : }
    1170             : /* }}} */
    1171             : 
    1172             : /* {{{ proto string image_type_to_extension(int imagetype [, bool include_dot])
    1173             :    Get file extension for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */
    1174          38 : PHP_FUNCTION(image_type_to_extension)
    1175             : {
    1176             :         long image_type;
    1177          38 :         zend_bool inc_dot=1;
    1178             : 
    1179          38 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &image_type, &inc_dot) == FAILURE) {
    1180           4 :                 RETURN_FALSE;
    1181             :         }
    1182             : 
    1183          34 :         switch (image_type) {
    1184             :                 case IMAGE_FILETYPE_GIF:
    1185           2 :                         RETURN_STRING(".gif" + !inc_dot, 1);
    1186             :                 case IMAGE_FILETYPE_JPEG:
    1187           2 :                         RETURN_STRING(".jpeg" + !inc_dot, 1);
    1188             :                 case IMAGE_FILETYPE_PNG:
    1189           2 :                         RETURN_STRING(".png" + !inc_dot, 1);
    1190             :                 case IMAGE_FILETYPE_SWF:
    1191             :                 case IMAGE_FILETYPE_SWC:
    1192           2 :                         RETURN_STRING(".swf" + !inc_dot, 1);
    1193             :                 case IMAGE_FILETYPE_PSD:
    1194           2 :                         RETURN_STRING(".psd" + !inc_dot, 1);
    1195             :                 case IMAGE_FILETYPE_BMP:
    1196             :                 case IMAGE_FILETYPE_WBMP:
    1197           4 :                         RETURN_STRING(".bmp" + !inc_dot, 1);
    1198             :                 case IMAGE_FILETYPE_TIFF_II:
    1199             :                 case IMAGE_FILETYPE_TIFF_MM:
    1200           4 :                         RETURN_STRING(".tiff" + !inc_dot, 1);
    1201             :                 case IMAGE_FILETYPE_IFF:
    1202           2 :                         RETURN_STRING(".iff" + !inc_dot, 1);
    1203             :                 case IMAGE_FILETYPE_JPC:
    1204           4 :                         RETURN_STRING(".jpc" + !inc_dot, 1);
    1205             :                 case IMAGE_FILETYPE_JP2:
    1206           2 :                         RETURN_STRING(".jp2" + !inc_dot, 1);
    1207             :                 case IMAGE_FILETYPE_JPX:
    1208           2 :                         RETURN_STRING(".jpx" + !inc_dot, 1);
    1209             :                 case IMAGE_FILETYPE_JB2:
    1210           2 :                         RETURN_STRING(".jb2" + !inc_dot, 1);
    1211             :                 case IMAGE_FILETYPE_XBM:
    1212           2 :                         RETURN_STRING(".xbm" + !inc_dot, 1);
    1213             :                 case IMAGE_FILETYPE_ICO:
    1214           0 :                         RETURN_STRING(".ico" + !inc_dot, 1);
    1215             :         }
    1216             : 
    1217           2 :         RETURN_FALSE;
    1218             : }
    1219             : /* }}} */
    1220             : 
    1221             : /* {{{ php_imagetype
    1222             :    detect filetype from first bytes */
    1223          87 : PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
    1224             : {
    1225             :         char tmp[12];
    1226             : 
    1227          87 :         if ( !filetype) filetype = tmp;
    1228          87 :         if((php_stream_read(stream, filetype, 3)) != 3) {
    1229           4 :                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
    1230           4 :                 return IMAGE_FILETYPE_UNKNOWN;
    1231             :         }
    1232             : 
    1233             : /* BYTES READ: 3 */
    1234          83 :         if (!memcmp(filetype, php_sig_gif, 3)) {
    1235           7 :                 return IMAGE_FILETYPE_GIF;
    1236          76 :         } else if (!memcmp(filetype, php_sig_jpg, 3)) {
    1237          31 :                 return IMAGE_FILETYPE_JPEG;
    1238          45 :         } else if (!memcmp(filetype, php_sig_png, 3)) {
    1239           7 :                 if (php_stream_read(stream, filetype+3, 5) != 5) {
    1240           0 :                         php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
    1241           0 :                         return IMAGE_FILETYPE_UNKNOWN;
    1242             :                 }
    1243           7 :                 if (!memcmp(filetype, php_sig_png, 8)) {
    1244           7 :                         return IMAGE_FILETYPE_PNG;
    1245             :                 } else {
    1246           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "PNG file corrupted by ASCII conversion");
    1247           0 :                         return IMAGE_FILETYPE_UNKNOWN;
    1248             :                 }
    1249          38 :         } else if (!memcmp(filetype, php_sig_swf, 3)) {
    1250           3 :                 return IMAGE_FILETYPE_SWF;
    1251          35 :         } else if (!memcmp(filetype, php_sig_swc, 3)) {
    1252           3 :                 return IMAGE_FILETYPE_SWC;
    1253          32 :         } else if (!memcmp(filetype, php_sig_psd, 3)) {
    1254           2 :                 return IMAGE_FILETYPE_PSD;
    1255          30 :         } else if (!memcmp(filetype, php_sig_bmp, 2)) {
    1256           7 :                 return IMAGE_FILETYPE_BMP;
    1257          23 :         } else if (!memcmp(filetype, php_sig_jpc, 3)) {
    1258           3 :                 return IMAGE_FILETYPE_JPC;
    1259             :         }
    1260             : 
    1261          20 :         if (php_stream_read(stream, filetype+3, 1) != 1) {
    1262           0 :                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
    1263           0 :                 return IMAGE_FILETYPE_UNKNOWN;
    1264             :         }
    1265             : /* BYTES READ: 4 */
    1266          20 :         if (!memcmp(filetype, php_sig_tif_ii, 4)) {
    1267           3 :                 return IMAGE_FILETYPE_TIFF_II;
    1268          17 :         } else if (!memcmp(filetype, php_sig_tif_mm, 4)) {
    1269           1 :                 return IMAGE_FILETYPE_TIFF_MM;
    1270          16 :         } else if (!memcmp(filetype, php_sig_iff, 4)) {
    1271           3 :                 return IMAGE_FILETYPE_IFF;
    1272          13 :         } else if (!memcmp(filetype, php_sig_ico, 4)) {
    1273           0 :                 return IMAGE_FILETYPE_ICO;
    1274             :         }
    1275             : 
    1276          13 :         if (php_stream_read(stream, filetype+4, 8) != 8) {
    1277           0 :                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
    1278           0 :                 return IMAGE_FILETYPE_UNKNOWN;
    1279             :         }
    1280             : /* BYTES READ: 12 */
    1281          13 :         if (!memcmp(filetype, php_sig_jp2, 12)) {
    1282           3 :                 return IMAGE_FILETYPE_JP2;
    1283             :         }
    1284             : 
    1285             : /* AFTER ALL ABOVE FAILED */
    1286          10 :         if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) {
    1287           1 :                 return IMAGE_FILETYPE_WBMP;
    1288             :         }
    1289           9 :         if (php_get_xbm(stream, NULL TSRMLS_CC)) {
    1290           1 :                 return IMAGE_FILETYPE_XBM;
    1291             :         }
    1292           8 :         return IMAGE_FILETYPE_UNKNOWN;
    1293             : }
    1294             : /* }}} */
    1295             : 
    1296          86 : static void php_getimagesize_from_stream(php_stream *stream, zval **info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
    1297             : {
    1298             :         char *temp;
    1299          86 :         int itype = 0;
    1300          86 :         struct gfxinfo *result = NULL;
    1301             : 
    1302          86 :         if (!stream) {
    1303           0 :                 RETURN_FALSE;
    1304             :         }
    1305             : 
    1306          86 :         itype = php_getimagetype(stream, NULL TSRMLS_CC);
    1307          86 :         switch( itype) {
    1308             :                 case IMAGE_FILETYPE_GIF:
    1309           7 :                         result = php_handle_gif(stream TSRMLS_CC);
    1310           7 :                         break;
    1311             :                 case IMAGE_FILETYPE_JPEG:
    1312          30 :                         if (info) {
    1313          27 :                                 result = php_handle_jpeg(stream, *info TSRMLS_CC);
    1314             :                         } else {
    1315           3 :                                 result = php_handle_jpeg(stream, NULL TSRMLS_CC);
    1316             :                         }
    1317          30 :                         break;
    1318             :                 case IMAGE_FILETYPE_PNG:
    1319           7 :                         result = php_handle_png(stream TSRMLS_CC);
    1320           7 :                         break;
    1321             :                 case IMAGE_FILETYPE_SWF:
    1322           3 :                         result = php_handle_swf(stream TSRMLS_CC);
    1323           3 :                         break;
    1324             :                 case IMAGE_FILETYPE_SWC:
    1325             : #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
    1326           3 :                         result = php_handle_swc(stream TSRMLS_CC);
    1327             : #else
    1328             :                         php_error_docref(NULL TSRMLS_CC, E_NOTICE, "The image is a compressed SWF file, but you do not have a static version of the zlib extension enabled");
    1329             : #endif
    1330           3 :                         break;
    1331             :                 case IMAGE_FILETYPE_PSD:
    1332           2 :                         result = php_handle_psd(stream TSRMLS_CC);
    1333           2 :                         break;
    1334             :                 case IMAGE_FILETYPE_BMP:
    1335           7 :                         result = php_handle_bmp(stream TSRMLS_CC);
    1336           7 :                         break;
    1337             :                 case IMAGE_FILETYPE_TIFF_II:
    1338           3 :                         result = php_handle_tiff(stream, NULL, 0 TSRMLS_CC);
    1339           3 :                         break;
    1340             :                 case IMAGE_FILETYPE_TIFF_MM:
    1341           1 :                         result = php_handle_tiff(stream, NULL, 1 TSRMLS_CC);
    1342           1 :                         break;
    1343             :                 case IMAGE_FILETYPE_JPC:
    1344           3 :                         result = php_handle_jpc(stream TSRMLS_CC);
    1345           3 :                         break;
    1346             :                 case IMAGE_FILETYPE_JP2:
    1347           3 :                         result = php_handle_jp2(stream TSRMLS_CC);
    1348           3 :                         break;
    1349             :                 case IMAGE_FILETYPE_IFF:
    1350           3 :                         result = php_handle_iff(stream TSRMLS_CC);
    1351           3 :                         break;
    1352             :                 case IMAGE_FILETYPE_WBMP:
    1353           1 :                         result = php_handle_wbmp(stream TSRMLS_CC);
    1354           1 :                         break;
    1355             :                 case IMAGE_FILETYPE_XBM:
    1356           1 :                         result = php_handle_xbm(stream TSRMLS_CC);
    1357           1 :                         break;
    1358             :                 case IMAGE_FILETYPE_ICO:
    1359           0 :                         result = php_handle_ico(stream TSRMLS_CC);
    1360             :                         break;
    1361             :                 default:
    1362             :                 case IMAGE_FILETYPE_UNKNOWN:
    1363             :                         break;
    1364             :         }
    1365             : 
    1366          86 :         if (result) {
    1367          74 :                 array_init(return_value);
    1368          74 :                 add_index_long(return_value, 0, result->width);
    1369          74 :                 add_index_long(return_value, 1, result->height);
    1370          74 :                 add_index_long(return_value, 2, itype);
    1371          74 :                 spprintf(&temp, 0, "width=\"%d\" height=\"%d\"", result->width, result->height);
    1372          74 :                 add_index_string(return_value, 3, temp, 0);
    1373             : 
    1374          74 :                 if (result->bits != 0) {
    1375          60 :                         add_assoc_long(return_value, "bits", result->bits);
    1376             :                 }
    1377          74 :                 if (result->channels != 0) {
    1378          43 :                         add_assoc_long(return_value, "channels", result->channels);
    1379             :                 }
    1380          74 :                 add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1);
    1381          74 :                 efree(result);
    1382             :         } else {
    1383          12 :                 RETURN_FALSE;
    1384             :         }
    1385             : }
    1386             : /* }}} */
    1387             : 
    1388             : #define FROM_DATA 0
    1389             : #define FROM_PATH 1
    1390             : 
    1391         117 : static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) {  /* {{{ */
    1392         117 :         zval **info = NULL;
    1393         117 :         php_stream *stream = NULL;
    1394             :         char *input;
    1395             :         int input_len;
    1396         117 :         const int argc = ZEND_NUM_ARGS();
    1397             : 
    1398         117 :         if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &input, &input_len, &info) == FAILURE) {
    1399           8 :                         return;
    1400             :         }
    1401             : 
    1402         109 :         if (argc == 2) {
    1403          67 :                         zval_dtor(*info);
    1404          67 :                         array_init(*info);
    1405             :         }
    1406             : 
    1407             : 
    1408         109 :         if (mode == FROM_PATH) {
    1409         108 :                 stream = php_stream_open_wrapper(input, "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH, NULL);
    1410             :         } else {
    1411           1 :                 stream = php_stream_memory_open(TEMP_STREAM_READONLY, input, input_len);
    1412             :         }
    1413             : 
    1414         109 :         if (!stream) {
    1415          23 :                    RETURN_FALSE;
    1416             :         }
    1417             : 
    1418          86 :         php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU);
    1419          86 :         php_stream_close(stream);
    1420             : }
    1421             : /* }}} */
    1422             : 
    1423             : /* {{{ proto array getimagesize(string imagefile [, array info])
    1424             :    Get the size of an image as 4-element array */
    1425         116 : PHP_FUNCTION(getimagesize)
    1426             : {
    1427         116 :         php_getimagesize_from_any(INTERNAL_FUNCTION_PARAM_PASSTHRU, FROM_PATH);
    1428         116 : }
    1429             : /* }}} */
    1430             : 
    1431             : /* {{{ proto array getimagesizefromstring(string data [, array info])
    1432             :    Get the size of an image as 4-element array */
    1433           1 : PHP_FUNCTION(getimagesizefromstring)
    1434             : {
    1435           1 :         php_getimagesize_from_any(INTERNAL_FUNCTION_PARAM_PASSTHRU, FROM_DATA);
    1436           1 : }
    1437             : 
    1438             : /*
    1439             :  * Local variables:
    1440             :  * tab-width: 4
    1441             :  * c-basic-offset: 4
    1442             :  * End:
    1443             :  * vim600: sw=4 ts=4 fdm=marker
    1444             :  * vim<600: sw=4 ts=4
    1445             :  */

Generated by: LCOV version 1.10

Generated at Mon, 15 Dec 2014 17:02:51 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.