src/PelIfd.php
private function safeSetThumbnail(PelDataWindow $d, $offset, $length)
    {
        /*
         * Load the thumbnail if both the offset and the length is
         * available.
         */
        if ($offset > 0 && $length > 0) {
            /*
             * Some images have a broken length, so we try to carefully
             * check the length before we store the thumbnail.
             */
            if ($offset + $length > $d->getSize()) {
                Pel::maybeThrow(
                    new PelIfdException(
                        'Thumbnail length %d bytes ' . 'adjusted to %d bytes.',
                        $length,
                        $d->getSize() - $offset
                    )
                );
                $length = $d->getSize() - $offset;
            }

            /* Now set the thumbnail normally. */
            try {
                $this->setThumbnail($d->getClone($offset, $length));
            } catch (PelDataWindowWindowException $e) {
                Pel::maybeThrow(new PelIfdException($e->getMessage()));
            }
        }
    }
private function safeSetThumbnail(PelDataWindow $d, $offset, $length)
    {
        /*
         * Load the thumbnail if both the offset and the length is
         * available.
         */
        if ($offset > 0 && $length > 0) {
            /*
             * Some images have a broken length, so we try to carefully
             * check the length before we store the thumbnail.
             */
            if ($offset + $length > $d->getSize()) {
                Pel::maybeThrow(
                    new PelIfdException(
                        'Thumbnail length %d bytes ' . 'adjusted to %d bytes.',
                        $length,
                        $d->getSize() - $offset
                    )
                );
                $length = $d->getSize() - $offset;
            }

            /* Now set the thumbnail normally. */
            try {
                $this->setThumbnail($d->getClone($offset, $length));
            } catch (PelDataWindowWindowException $e) {
                Pel::maybeThrow(new PelIfdException($e->getMessage()));
            }
        }
    }
private function safeSetThumbnail ( PelDataWindow $ d , $ offset , $ length ) { /*
         * Load the thumbnail if both the offset and the length is
         * available.
         */ if ( $ offset > 0 && $ length > 0 ) { /*
             * Some images have a broken length, so we try to carefully
             * check the length before we store the thumbnail.
             */ if ( $ offset + $ length > $ d -> getSize ( ) ) { Pel :: maybeThrow ( new PelIfdException ( 'Thumbnail length %d bytes ' . 'adjusted to %d bytes.' , $ length , $ d -> getSize ( ) - $ offset ) ) ; $ length = $ d -> getSize ( ) - $ offset ; } /* Now set the thumbnail normally. */ try { $ this -> setThumbnail ( $ d -> getClone ( $ offset , $ length ) ) ; } catch ( PelDataWindowWindowException $ e ) { Pel :: maybeThrow ( new PelIfdException ( $ e -> getMessage ( ) ) ) ; } } }
Extract thumbnail data safely.

It is safe to call this method repeatedly with either the offset
or the length set to zero, since it requires both of these
arguments to be positive before the thumbnail is extracted.

When both parameters are set it will check the length against the
available data and adjust as necessary. Only then is the
thumbnail data loaded.

@param PelDataWindow $d
the data from which the thumbnail will be
extracted.

@param int $offset
the offset into the data.

@param int $length
the length of the thumbnail.
Extract thumbnail data safely .