mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 06:40:08 +02:00
Identify the few unsafe narrowing conversions from sampleCount...
... I believe this list of four places is exhaustive. There are many, many more safe narrowings that I examined. This resulted from changing the definition of sampleCount in my builds so that narrowing conversions failed to compile without some fixes, and I examined and fixed every place. The rest of that work is not yet shared.
This commit is contained in:
parent
37687c589f
commit
1189cfd62a
@ -334,10 +334,14 @@ bool EffectSBSMS::Process()
|
|||||||
(long)((float)(processPresamples)*(srTrack/srProcess)));
|
(long)((float)(processPresamples)*(srTrack/srProcess)));
|
||||||
rb.offset = start - trackPresamples;
|
rb.offset = start - trackPresamples;
|
||||||
rb.end = trackEnd;
|
rb.end = trackEnd;
|
||||||
rb.iface = std::make_unique<SBSMSEffectInterface>(rb.resampler.get(),
|
rb.iface = std::make_unique<SBSMSEffectInterface>
|
||||||
&rateSlide,&pitchSlide,
|
(rb.resampler.get(), &rateSlide, &pitchSlide,
|
||||||
bPitchReferenceInput,
|
bPitchReferenceInput,
|
||||||
samplesToProcess,processPresamples,
|
// UNSAFE_SAMPLE_COUNT_TRUNCATION
|
||||||
|
// The argument type is only long!
|
||||||
|
static_cast<long> ( static_cast<size_t> (
|
||||||
|
samplesToProcess ) ),
|
||||||
|
processPresamples,
|
||||||
rb.quality.get());
|
rb.quality.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ enum
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Protect Nyquist from selections greater than 2^31 samples (bug 439)
|
// Protect Nyquist from selections greater than 2^31 samples (bug 439)
|
||||||
#define NYQ_MAX_LEN ((sampleCount) 2147483647)
|
#define NYQ_MAX_LEN (std::numeric_limits<long>::max())
|
||||||
|
|
||||||
#define UNINITIALIZED_CONTROL ((double)99999999.99)
|
#define UNINITIALIZED_CONTROL ((double)99999999.99)
|
||||||
|
|
||||||
@ -630,8 +630,12 @@ bool NyquistEffect::Process()
|
|||||||
mCurLen = (sampleCount)(end - mCurStart[0]);
|
mCurLen = (sampleCount)(end - mCurStart[0]);
|
||||||
|
|
||||||
if (mCurLen > NYQ_MAX_LEN) {
|
if (mCurLen > NYQ_MAX_LEN) {
|
||||||
wxMessageBox(_("Selection too long for Nyquist code.\nMaximum allowed selection is 2147483647 samples\n(about 13.5 hours at 44100 Hz sample rate)."),
|
float hours = (float)NYQ_MAX_LEN / (44100 * 60 * 60);
|
||||||
_("Nyquist Error"), wxOK | wxCENTRE);
|
const auto message = wxString::Format(
|
||||||
|
_("Selection too long for Nyquist code.\nMaximum allowed selection is %ld samples\n(about %.1f hours at 44100 Hz sample rate)."),
|
||||||
|
(long)NYQ_MAX_LEN, hours
|
||||||
|
);
|
||||||
|
wxMessageBox(message, _("Nyquist Error"), wxOK | wxCENTRE);
|
||||||
if (!mProjectChanged)
|
if (!mProjectChanged)
|
||||||
em.SetSkipStateFlag(true);
|
em.SetSkipStateFlag(true);
|
||||||
return false;
|
return false;
|
||||||
@ -959,11 +963,21 @@ bool NyquistEffect::ProcessOne()
|
|||||||
nyx_set_audio_params(mCurTrack[0]->GetRate(), 0);
|
nyx_set_audio_params(mCurTrack[0]->GetRate(), 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nyx_set_audio_params(mCurTrack[0]->GetRate(), mCurLen);
|
// UNSAFE_SAMPLE_COUNT_TRUNCATION
|
||||||
|
// Danger! Truncation of long long to long!
|
||||||
|
// Don't say we didn't warn you!
|
||||||
|
|
||||||
|
// Note mCurLen was elsewhere limited to mMaxLen, which is normally
|
||||||
|
// the greatest long value, and yet even mMaxLen may be experimentally
|
||||||
|
// increased with a nyquist comment directive.
|
||||||
|
// See the parsing of "maxlen"
|
||||||
|
|
||||||
|
auto curLen = (long)(static_cast<long long>(mCurLen));
|
||||||
|
nyx_set_audio_params(mCurTrack[0]->GetRate(), curLen);
|
||||||
|
|
||||||
nyx_set_input_audio(StaticGetCallback, (void *)this,
|
nyx_set_input_audio(StaticGetCallback, (void *)this,
|
||||||
mCurNumChannels,
|
mCurNumChannels,
|
||||||
mCurLen, mCurTrack[0]->GetRate());
|
curLen, mCurTrack[0]->GetRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore the Nyquist sixteenth note symbol for Generate plugins.
|
// Restore the Nyquist sixteenth note symbol for Generate plugins.
|
||||||
|
@ -522,7 +522,12 @@ bool VampEffect::Process()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime(ls, (int)(mRate + 0.5));
|
// UNSAFE_SAMPLE_COUNT_TRUNCATION
|
||||||
|
// Truncation in case of very long tracks!
|
||||||
|
Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime(
|
||||||
|
(long) static_cast<long long>( ls ),
|
||||||
|
(int)(mRate + 0.5)
|
||||||
|
);
|
||||||
|
|
||||||
Vamp::Plugin::FeatureSet features = mPlugin->process(data, timestamp);
|
Vamp::Plugin::FeatureSet features = mPlugin->process(data, timestamp);
|
||||||
AddFeatures(ltrack, features);
|
AddFeatures(ltrack, features);
|
||||||
|
@ -848,7 +848,9 @@ void NumericConverter::ValueToControls(double rawValue, bool nearest /* = true *
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (t_int >= 0) {
|
if (t_int >= 0) {
|
||||||
value = (t_int / mFields[i].base);
|
// UNSAFE_SAMPLE_COUNT_TRUNCATION
|
||||||
|
// truncation danger!
|
||||||
|
value = (static_cast<long long>( t_int ) / mFields[i].base);
|
||||||
if (mFields[i].range > 0)
|
if (mFields[i].range > 0)
|
||||||
value = value % mFields[i].range;
|
value = value % mFields[i].range;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user