Skip to content

Commit 101fec1

Browse files
committed
Add validation checks for channel count and file size in BinaryFileSource
1 parent ce3e4f1 commit 101fec1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Plugins/LfpViewer/LfpDisplayOptions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,11 @@ void LfpDisplayOptions::comboBoxChanged (ComboBox* cb)
12681268
selectedVoltageRange[selectedChannelType] = cb->getSelectedId();
12691269
selectedVoltageRangeValues[selectedChannelType] = cb->getText();
12701270
canvasSplit->redraw();
1271+
1272+
if (selectedChannelType == ContinuousChannel::Type::AUX && isAuxAutoScaleEnabled())
1273+
rangeSelectionLabel->setText ("Range", dontSendNotification);
1274+
else
1275+
rangeSelectionLabel->setText ("Range (" + rangeUnits[selectedChannelType] + ")", dontSendNotification);
12711276
}
12721277
else if (cb == spreadSelection.get())
12731278
{

Source/Processors/FileReader/BinaryFileSource/BinaryFileSource.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ void BinaryFileSource::fillRecordInfo()
131131
}
132132

133133
int numChannels = record[idNumChannels];
134+
135+
// if numchannels is not equal to the size of channels var, skip this record
136+
if (numChannels != channels.size())
137+
{
138+
LOGE ("Number of channels mismatch in stream: ", streamName);
139+
continue;
140+
}
141+
142+
// if numSamples is not a whole number, skip this record
143+
if (dataFile.getSize() % (numChannels * sizeof (int16)) != 0)
144+
{
145+
LOGE ("File size is not consistent with number of channels in stream: ", streamName);
146+
continue;
147+
}
148+
134149
int64 numSamples = (dataFile.getSize() / numChannels) / sizeof (int16);
135150

136151
info.name = streamName;

Source/Processors/FileReader/FileReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bool FileReader::setFile (String fullpath, bool shouldUpdateSignalChain)
286286
if (isEmptyFile)
287287
{
288288
input = nullptr;
289-
showWarningAsync ("Failed to open file", "Continuous data file is missing or empty.");
289+
showWarningAsync ("Failed to open file", "Continuous data file is missing, empty, or invalid.");
290290
CoreServices::sendStatusMessage ("Empty file. Ignoring open operation");
291291

292292
return false;

0 commit comments

Comments
 (0)