github-tools / github-release-notes

Node module to create a release or a changelog from a tag and uses issues or commits to creating the release notes.
https://github-tools.github.io/github-release-notes/
GNU General Public License v3.0
880 stars 325 forks source link

bug: Index will go out of range when RANGE > 2 #288

Closed HarikrishnanBalagopal closed 3 years ago

HarikrishnanBalagopal commented 3 years ago

Bug

There is a index out of range bug here: https://github.com/github-tools/github-release-notes/blob/8c5affc496f7b787fa0793ce3f7b812354d5679f/lib/src/Gren.js#L1096-L1101 The for loop index goes all the way to length - 2 (2nd last element) and we are accessing indices i and i + 1 in the loop. This only works when RANGE = 2.

When RANGE > 2 we will access indices i and i + RANGE - 1 which will end up outside the range of the array because we are not changing the for loop end condition. Example:

RANGE = 3
length = 4
for loop i goes to length - 2 = 4 - 2 = 2
i = 2
i + RANGE - 1 = i + 3 - 1 = i + 2 = 2 + 2 = 4
...sortedReleaseDates[4], // gives a index out of range exception 

Fix

        for (let i = 0; i < sortedReleaseDates.length - RANGE + 1; i++) {