Ejemplo n.º 1
0
        private void ProcessExifDir(byte[] section, int offsetDir, int offsetBase, int length, int depth, ExifIFD ifd)
        {
            if (depth > 4)
            {
                // corrupted Exif header...
                return;
            }

            ushort numEntries = ExifIO.ReadUShort(section, offsetDir, littleEndian);

            if (offsetDir + 2 + 12 * numEntries >= offsetDir + length)
            {
                // too long
                return;
            }

            int offset = 0;

            for (int de = 0; de < numEntries; ++de)
            {
                offset = DirOffset(offsetDir, de);
                ExifTag exifTag = new ExifTag(section, offset, offsetBase, length, littleEndian);

                if (!exifTag.IsValid)
                {
                    continue;
                }

                switch (exifTag.Tag)
                {
                case (int)ExifIFD.Exif:
                {
                    int dirStart = offsetBase + exifTag.GetInt(0);
                    if (dirStart <= offsetBase + length)
                    {
                        ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Exif);
                    }
                } break;

                case (int)ExifIFD.Gps:
                {
                    int dirStart = offsetBase + exifTag.GetInt(0);
                    if (dirStart <= offsetBase + length)
                    {
                        ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Gps);
                    }
                } break;

                default:
                {
                    exifTag.Populate(info, ifd);
                } break;
                }
            }

            // final link defined?
            offset = DirOffset(offsetDir, numEntries) + 4;
            if (offset <= offsetBase + length)
            {
                offset = ExifIO.ReadInt(section, offsetDir + 2 + 12 * numEntries, littleEndian);
                if (offset > 0)
                {
                    int subDirStart = offsetBase + offset;
                    if (subDirStart <= offsetBase + length && subDirStart >= offsetBase)
                    {
                        ProcessExifDir(section, subDirStart, offsetBase, length, depth + 1, ifd);
                    }
                }
            }

            if (info.ThumbnailData == null && info.ThumbnailOffset > 0 && info.ThumbnailSize > 0)
            {
                // store it.
                info.ThumbnailData = new byte[info.ThumbnailSize];
                Array.Copy(section, offsetBase + info.ThumbnailOffset, info.ThumbnailData, 0, info.ThumbnailSize);
            }
        }
Ejemplo n.º 2
0
        private void ProcessExifDir(byte[] section, int offsetDir, int offsetBase, int length, int depth, ExifIFD ifd)
        {
            if (depth > 4)
            {
                // corrupted Exif header...
                return;
            }

            ushort numEntries = ExifIO.ReadUShort(section, offsetDir, littleEndian);
            if (offsetDir + 2 + 12 * numEntries >= offsetDir + length)
            {
                // too long
                return;
            }

            int offset = 0;

            for (int de = 0; de < numEntries; ++de)
            {
                offset = DirOffset(offsetDir, de);
                ExifTag exifTag = new ExifTag(section, offset, offsetBase, length, littleEndian);

                if (!exifTag.IsValid)
                    continue;

                switch (exifTag.Tag)
                {
                    case (int)ExifIFD.Exif:
                        {
                            int dirStart = offsetBase + exifTag.GetInt(0);
                            if (dirStart <= offsetBase + length)
                            {
                                ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Exif);
                            }
                        } break;
                    case (int)ExifIFD.Gps:
                        {
                            int dirStart = offsetBase + exifTag.GetInt(0);
                            if (dirStart <= offsetBase + length)
                            {
                                ProcessExifDir(section, dirStart, offsetBase, length, depth + 1, ExifIFD.Gps);
                            }
                        } break;
                    default:
                        {
                            exifTag.Populate(info, ifd);
                        } break;
                }
            }

            // final link defined?
            offset = DirOffset(offsetDir, numEntries) + 4;
            if (offset <= offsetBase + length)
            {
                offset = ExifIO.ReadInt(section, offsetDir + 2 + 12 * numEntries, littleEndian);
                if (offset > 0)
                {
                    int subDirStart = offsetBase + offset;
                    if (subDirStart <= offsetBase + length && subDirStart >= offsetBase)
                    {
                        ProcessExifDir(section, subDirStart, offsetBase, length, depth + 1, ifd);
                    }
                }
            }

            if (info.ThumbnailData == null && info.ThumbnailOffset > 0 && info.ThumbnailSize > 0)
            {
                // store it.
                info.ThumbnailData = new byte[info.ThumbnailSize];
                Array.Copy(section, offsetBase + info.ThumbnailOffset, info.ThumbnailData, 0, info.ThumbnailSize);
            }
        }
Ejemplo n.º 3
0
        private void ProcessExifDir(byte[] section, int offsetDir, int offsetBase, int length, int depth, ExifIFD ifd, long sectionStart)
        {
            if (depth > 4)
            {
                return;
            }
            ushort num1 = ExifIO.ReadUShort(section, offsetDir, this.littleEndian);

            if (offsetDir + 2 + 12 * (int)num1 >= offsetDir + length)
            {
                return;
            }
            for (int num2 = 0; num2 < (int)num1; ++num2)
            {
                int     sectionOffset = this.DirOffset(offsetDir, num2);
                ExifTag exifTag       = new ExifTag(section, sectionOffset, offsetBase, length, this.littleEndian);
                if (exifTag.IsValid)
                {
                    switch (exifTag.Tag)
                    {
                    case 34665:
                        int offsetDir1 = offsetBase + exifTag.GetInt(0);
                        if (offsetDir1 <= offsetBase + length)
                        {
                            this.ProcessExifDir(section, offsetDir1, offsetBase, length, depth + 1, ExifIFD.Exif, sectionStart);
                            continue;
                        }
                        continue;

                    case 34853:
                        int offsetDir2 = offsetBase + exifTag.GetInt(0);
                        if (offsetDir2 <= offsetBase + length)
                        {
                            this.ProcessExifDir(section, offsetDir2, offsetBase, length, depth + 1, ExifIFD.Gps, sectionStart);
                            continue;
                        }
                        continue;

                    default:
                        exifTag.Populate(this.info, ifd, sectionStart);
                        continue;
                    }
                }
            }
            if (this.DirOffset(offsetDir, (int)num1) + 4 <= offsetBase + length)
            {
                int num2 = ExifIO.ReadInt(section, offsetDir + 2 + 12 * (int)num1, this.littleEndian);
                if (num2 > 0)
                {
                    int offsetDir1 = offsetBase + num2;
                    if (offsetDir1 <= offsetBase + length && offsetDir1 >= offsetBase)
                    {
                        this.ProcessExifDir(section, offsetDir1, offsetBase, length, depth + 1, ifd, sectionStart);
                    }
                }
            }
            if (this.info.ThumbnailData != null || this.info.ThumbnailOffset <= 0 || this.info.ThumbnailSize <= 0)
            {
                return;
            }
            this.info.ThumbnailData = new byte[this.info.ThumbnailSize];
            Array.Copy((Array)section, offsetBase + this.info.ThumbnailOffset, (Array)this.info.ThumbnailData, 0, this.info.ThumbnailSize);
        }