| OLD | NEW |
| 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
| 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 4 * | 4 * |
| 5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
| 6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
| 7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
| 8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
| 9 * | 9 * |
| 10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 // until we find an image separator, but GIF89a says such | 481 // until we find an image separator, but GIF89a says such |
| 482 // a file is corrupt. We follow Mozilla's implementation and | 482 // a file is corrupt. We follow Mozilla's implementation and |
| 483 // proceed as if the file were correctly terminated, so the | 483 // proceed as if the file were correctly terminated, so the |
| 484 // GIF will display. | 484 // GIF will display. |
| 485 GETN(0, GIFDone); | 485 GETN(0, GIFDone); |
| 486 break; | 486 break; |
| 487 } | 487 } |
| 488 | 488 |
| 489 case GIFExtension: { | 489 case GIFExtension: { |
| 490 size_t bytesInBlock = currentComponent[1]; | 490 size_t bytesInBlock = currentComponent[1]; |
| 491 GIFState es = GIFSkipBlock; | 491 GIFState exceptionState = GIFSkipBlock; |
| 492 | 492 |
| 493 switch (*currentComponent) { | 493 switch (*currentComponent) { |
| 494 case 0xf9: | 494 case 0xf9: |
| 495 es = GIFControlExtension; | 495 exceptionState = GIFControlExtension; |
| 496 // The GIF spec mandates that the GIFControlExtension header blo
ck length is 4 bytes, | 496 // The GIF spec mandates that the GIFControlExtension header blo
ck length is 4 bytes, |
| 497 // and the parser for this block reads 4 bytes, so we must enfor
ce that the buffer | 497 // and the parser for this block reads 4 bytes, so we must enfor
ce that the buffer |
| 498 // contains at least this many bytes. If the GIF specifies a dif
ferent length, we | 498 // contains at least this many bytes. If the GIF specifies a dif
ferent length, we |
| 499 // allow that, so long as it's larger; the additional data will
simply be ignored. | 499 // allow that, so long as it's larger; the additional data will
simply be ignored. |
| 500 bytesInBlock = std::max(bytesInBlock, static_cast<size_t>(4)); | 500 bytesInBlock = std::max(bytesInBlock, static_cast<size_t>(4)); |
| 501 break; | 501 break; |
| 502 | 502 |
| 503 // The GIF spec also specifies the lengths of the following two exte
nsions' headers | 503 // The GIF spec also specifies the lengths of the following two exte
nsions' headers |
| 504 // (as 12 and 11 bytes, respectively). Because we ignore the plain t
ext extension entirely | 504 // (as 12 and 11 bytes, respectively). Because we ignore the plain t
ext extension entirely |
| 505 // and sanity-check the actual length of the application extension h
eader before reading it, | 505 // and sanity-check the actual length of the application extension h
eader before reading it, |
| 506 // we allow GIFs to deviate from these values in either direction. T
his is important for | 506 // we allow GIFs to deviate from these values in either direction. T
his is important for |
| 507 // real-world compatibility, as GIFs in the wild exist with applicat
ion extension headers | 507 // real-world compatibility, as GIFs in the wild exist with applicat
ion extension headers |
| 508 // that are both shorter and longer than 11 bytes. | 508 // that are both shorter and longer than 11 bytes. |
| 509 case 0x01: | 509 case 0x01: |
| 510 // ignoring plain text extension | 510 // ignoring plain text extension |
| 511 break; | 511 break; |
| 512 | 512 |
| 513 case 0xff: | 513 case 0xff: |
| 514 es = GIFApplicationExtension; | 514 exceptionState = GIFApplicationExtension; |
| 515 break; | 515 break; |
| 516 | 516 |
| 517 case 0xfe: | 517 case 0xfe: |
| 518 es = GIFConsumeComment; | 518 exceptionState = GIFConsumeComment; |
| 519 break; | 519 break; |
| 520 } | 520 } |
| 521 | 521 |
| 522 if (bytesInBlock) | 522 if (bytesInBlock) |
| 523 GETN(bytesInBlock, es); | 523 GETN(bytesInBlock, exceptionState); |
| 524 else | 524 else |
| 525 GETN(1, GIFImageStart); | 525 GETN(1, GIFImageStart); |
| 526 break; | 526 break; |
| 527 } | 527 } |
| 528 | 528 |
| 529 case GIFConsumeBlock: { | 529 case GIFConsumeBlock: { |
| 530 if (!*currentComponent) | 530 if (!*currentComponent) |
| 531 GETN(1, GIFImageStart); | 531 GETN(1, GIFImageStart); |
| 532 else | 532 else |
| 533 GETN(*currentComponent, GIFSkipBlock); | 533 GETN(*currentComponent, GIFSkipBlock); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 rowIter = rowBuffer.begin(); | 792 rowIter = rowBuffer.begin(); |
| 793 rowsRemaining = m_frameContext->height(); | 793 rowsRemaining = m_frameContext->height(); |
| 794 | 794 |
| 795 // Clearing the whole suffix table lets us be more tolerant of bad data. | 795 // Clearing the whole suffix table lets us be more tolerant of bad data. |
| 796 for (int i = 0; i < clearCode; ++i) { | 796 for (int i = 0; i < clearCode; ++i) { |
| 797 suffix[i] = i; | 797 suffix[i] = i; |
| 798 suffixLength[i] = 1; | 798 suffixLength[i] = 1; |
| 799 } | 799 } |
| 800 return true; | 800 return true; |
| 801 } | 801 } |
| OLD | NEW |