Skip to content

Commit

Permalink
Fixed buffer overflow bug with center=true
Browse files Browse the repository at this point in the history
  • Loading branch information
pl0xz0rz committed Oct 27, 2023
1 parent ea61762 commit 1206442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions RootInteractive/Tools/RDataFrame/RollingSum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ OutputIt rolling_sum(InputIt first, InputIt last, OutputIt d_first, size_t radiu
++d_first;
}
if(center){
for(;count>0; --count){
for(;count>n_skip; --count){
init = std::move(init) - *first;
++first;
*d_first = init;
Expand Down Expand Up @@ -98,7 +98,7 @@ OutputIt rolling_mean(InputIt first, InputIt last, OutputIt d_first, size_t radi
++d_first;
}
if(center){
for(;count>0; --count){
for(;count>n_skip; --count){
init = std::move(init) - *first;
++first;
*d_first = init / count;
Expand All @@ -120,8 +120,10 @@ OutputIt rolling_variance(InputIt first, InputIt last, OutputIt d_first, size_t
cur = *window_end;
init = std::move(init) + cur;
sum_sq = std::move(sum_sq) + cur*cur;
*d_first = (sum_sq-init*init/count)/count;
++d_first;
if(count > n_skip || !center){
*d_first = (sum_sq-init*init/count)/count;
++d_first;
}
}
while(window_end < last){
cur = *window_end;
Expand All @@ -135,13 +137,16 @@ OutputIt rolling_variance(InputIt first, InputIt last, OutputIt d_first, size_t
*d_first = (sum_sq-init*init/count)/count;
++d_first;
}
for(;count>0; --count){
if(center){
for(;count>n_skip; --count){
cur = *window_end;
init = std::move(init) - cur;
sum_sq = std::move(sum_sq) - cur*cur;
++first
*d_first = (sum_sq-init*init/count)/count;
++d_first;
}
}
return d_first;
}

Expand Down
4 changes: 3 additions & 1 deletion RootInteractive/Tools/RDataFrame/test_RDataFrame_Array.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@ def test_define2(rdf):
print(rdf.Mean("arrayRollingSum1D0").GetValue())
rdf = makeDefine("arrayRollingMean1D0", "rollingMean(array1D0, 5, 0)[4:]-array1D0[2:-2]", rdf, None, 3)
print(rdf.Sum("arrayRollingMean1D0").GetValue())
rdf = makeDefine("arrayRollingMean1D1", "abs(rollingMean(array1D0, 5, 0, center=True)[4:]-array1D0[2:-2])", rdf, None, 3)
rdf = makeDefine("arrayRollingMean1D1", "abs(rollingMean(array1D0, 5, 0, center=True)[2:-2]-array1D0[2:-2])", rdf, None, 3)
print(rdf.Sum("arrayRollingMean1D1").GetValue())
rdf = makeDefine("arrayRollingMean1D2", "abs(rollingMean(array1D0, 2.5, time=array1D0)[2:-2]-array1D0[2:-2])", rdf, None, 3)
print(rdf.Sum("arrayRollingMean1D2").GetValue())
rdf = makeDefine("arrayRollingStd1D0", "abs(rollingStd(array1D0, 5)[2:-2]-10)", rdf, None, 3)
print(rdf.Sum("arrayRollingStd1D0").GetValue())
return rdf

def test_exception(rdf):
Expand Down

0 comments on commit 1206442

Please sign in to comment.