History

Add range checking to all stages of the pattern reader.

Christopher Snowhill committed 9 years ago

Commit d0a01261 parent 76ead851 file · +24 −9Browse files

Unified · Split

src/it/itread.c+24−9
@@ -825,7 +825,7 @@ static int it_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, unsigned char *buff · 824 unmodified lines
825825
826826 while (bufpos < buflen) {
827827 unsigned char b = buffer[bufpos++];
828−
828+
829829 if (b == 0) {
830830 /* End of row */
831831 IT_SET_END_ROW(entry);
@@ -841,31 +841,46 @@ static int it_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, unsigned char *buff · 9 unmodified lines
841841
842842 channel = (b - 1) & 63;
843843
844− if (b & 128)
844+ if (b & 128) {
845+ if (bufpos >= buflen)
846+ return -1;
847+
845848 cmask[channel] = mask = buffer[bufpos++];
846− else
849+ } else
847850 mask = cmask[channel];
848851
849852 if (mask) {
850853 entry->mask = (mask & 15) | (mask >> 4);
851854 entry->channel = channel;
852855
853− if (mask & IT_ENTRY_NOTE)
856+ if (mask & IT_ENTRY_NOTE) {
857+ if (bufpos >= buflen)
858+ return -1;
859+
854860 cnote[channel] = entry->note = buffer[bufpos++];
855− else if (mask & (IT_ENTRY_NOTE << 4))
861+ } else if (mask & (IT_ENTRY_NOTE << 4))
856862 entry->note = cnote[channel];
857863
858− if (mask & IT_ENTRY_INSTRUMENT)
864+ if (mask & IT_ENTRY_INSTRUMENT) {
865+ if (bufpos >= buflen)
866+ return -1;
867+
859868 cinstrument[channel] = entry->instrument = buffer[bufpos++];
860− else if (mask & (IT_ENTRY_INSTRUMENT << 4))
869+ } else if (mask & (IT_ENTRY_INSTRUMENT << 4))
861870 entry->instrument = cinstrument[channel];
862871
863− if (mask & IT_ENTRY_VOLPAN)
872+ if (mask & IT_ENTRY_VOLPAN) {
873+ if (bufpos >= buflen)
874+ return -1;
875+
864876 cvolpan[channel] = entry->volpan = buffer[bufpos++];
865− else if (mask & (IT_ENTRY_VOLPAN << 4))
877+ } else if (mask & (IT_ENTRY_VOLPAN << 4))
866878 entry->volpan = cvolpan[channel];
867879
868880 if (mask & IT_ENTRY_EFFECT) {
881+ if (bufpos + 1 >= buflen)
882+ return -1;
883+
869884 ceffect[channel] = entry->effect = buffer[bufpos++];
870885 ceffectvalue[channel] = entry->effectvalue = buffer[bufpos++];
871886 } else {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t