Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decimation: Prevent buffer overflow #9367

Merged
merged 1 commit into from Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/plugin.decimation.js
Expand Up @@ -46,7 +46,7 @@ function lttbDecimation(data, start, count, availableWidth, options) {

// Adding offset
const rangeOffs = Math.floor(i * bucketWidth) + 1 + start;
const rangeTo = Math.floor((i + 1) * bucketWidth) + 1 + start;
const rangeTo = Math.min(Math.floor((i + 1) * bucketWidth) + 1, count) + start;
const {x: pointAx, y: pointAy} = data[a];

// Note that this is changed from the original algorithm which initializes these
Expand Down
36 changes: 36 additions & 0 deletions test/specs/plugin.decimation.tests.js
Expand Up @@ -179,5 +179,41 @@ describe('Plugin.decimation', function() {
expect(chart.data.datasets[0].data[3].x).toBe(originalData[5].x);
expect(chart.data.datasets[0].data[4].x).toBe(originalData[6].x);
});

it('should not crash with uneven points', function() {
const data = [];
for (let i = 0; i < 15552; i++) {
data.push({x: i, y: i});
}

function createChart() {
return window.acquireChart({
type: 'line',
data: {
datasets: [{
data
}]
},
options: {
devicePixelRatio: 1.25,
parsing: false,
scales: {
x: {
type: 'linear'
}
},
plugins: {
decimation: {
enabled: true,
algorithm: 'lttb'
}
}
}
}, {
canvas: {width: 511, height: 511},
});
}
expect(createChart).not.toThrow();
});
});
});