-
Notifications
You must be signed in to change notification settings - Fork 123
Description
The following input can create a infinite loop inside jpeg-js causing it to never return:
const jpeg = require('jpeg-js');
let buf = Buffer.from( 'ffd8ffc1f151d800ff51d800ffdaffde', 'hex' );
jpeg.decode( buf );
Based on some preliminary debugging it appears to be related to the following code:
Lines 579 to 589 in b58cc11
var maxH = 0, maxV = 0; | |
var component, componentId; | |
for (componentId in frame.components) { | |
if (frame.components.hasOwnProperty(componentId)) { | |
component = frame.components[componentId]; | |
if (maxH < component.h) maxH = component.h; | |
if (maxV < component.v) maxV = component.v; | |
} | |
} | |
var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / maxH); | |
var mcusPerColumn = Math.ceil(frame.scanLines / 8 / maxV); |
Here maxH
and maxV
are initialized to zero, but since there are no components, the values are never modified, leading to a divide by zero error in the last two line (which set mcusPerLine
and mcusPerColumn
to Infinity
).
These values are later used inside the decodeAsScan()
function, where the following loop condition never evaluates to false since mcuExpected
is set to frame.mcusPerLine * frame.mcusPerColumn
(i.e. Infinity * Infinity
) at line 292 in /lib/decoder.js
.
Line 297 in b58cc11
while (mcu < mcuExpected) { |
found using jsfuzz