Skip to content

Commit 3403630

Browse files
committed
Merge pull request mozilla#2021 from yurydelendik/issue-1877
Merges new jpgjs: fixes invalid JPEG marker.
2 parents a98787e + ac0ae3e commit 3403630

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

external/jpgjs/LICENSE

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11

2-
Copyright (C) 2011 by notmasteryet
2+
Copyright (C) 2011 notmasteryet
33

4-
Contributors: Yury Delendik
5-
Brendan Dahl <bdahl@mozilla.com>
4+
Contributors: Yury Delendik <ydelendik@mozilla.com>
5+
Brendan Dahl <bdahl@mozilla.com>
66

7-
Permission is hereby granted, free of charge, to any person obtaining
8-
a copy of this software and associated documentation files (the
9-
"Software"), to deal in the Software without restriction, including
10-
without limitation the rights to use, copy, modify, merge, publish,
11-
distribute, sublicense, and/or sell copies of the Software, and to
12-
permit persons to whom the Software is furnished to do so, subject to
13-
the following conditions:
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
1410

15-
The above copyright notice and this permission notice shall be
16-
included in all copies or substantial portions of the Software.
11+
http://www.apache.org/licenses/LICENSE-2.0
1712

18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.

external/jpgjs/jpg.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
22
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
3+
/*
4+
Copyright 2011 notmasteryet
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
318

419
// - The JPEG specification can be found in the ITU CCITT Recommendation T.81
520
// (www.w3.org/Graphics/JPEG/itu-t81.pdf)
@@ -627,8 +642,9 @@ var JpegImage = (function jpegImage() {
627642
break;
628643

629644
case 0xFFDB: // DQT (Define Quantization Tables)
630-
var quantizationTableCount = Math.floor((readUint16() - 2) / 65);
631-
for (i = 0; i < quantizationTableCount; i++) {
645+
var quantizationTablesLength = readUint16();
646+
var quantizationTablesEnd = quantizationTablesLength + offset - 2;
647+
while (offset < quantizationTablesEnd) {
632648
var quantizationTableSpec = data[offset++];
633649
var tableData = new Int32Array(64);
634650
if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
@@ -721,6 +737,13 @@ var JpegImage = (function jpegImage() {
721737
offset += processed;
722738
break;
723739
default:
740+
if (data[offset - 3] == 0xFF &&
741+
data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
742+
// could be incorrect encoding -- last 0xFF byte of the previous
743+
// block was eaten by the encoder
744+
offset -= 3;
745+
break;
746+
}
724747
throw "unknown JPEG marker " + fileMarker.toString(16);
725748
}
726749
fileMarker = readUint16();

0 commit comments

Comments
 (0)