joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 71 forks source link

Segfault in window_idx #263

Closed TomAndrews closed 6 years ago

TomAndrews commented 6 years ago

Description

I've been seeing intermitted segfaults in my R code recently. One gave the following output:

0:01:13.457  *** caught segfault ***
00:01:13.457 address 0x180, cause 'memory not mapped'
00:01:13.458 
00:01:13.458 Traceback:
00:01:13.458  1: window_idx(x, index. = i)
00:01:13.458  2: `[.xts`(isTrading, time(data), colnames(data))

Expected behavior

No segfault!

Minimal, reproducible example

I can't reproduce the segfault but you can see the illegal read in valgrind (starting R with R -d valgrind)

library(xts)
ts1 <- .xts(1:10000, 1:10000)
ts2 <- .xts(1:20000, 1:20000)
gctorture(TRUE)
invisible(ts2[index(ts1)])

==47968== Invalid read of size 1
==47968==    at 0x4ED66AE: Rf_getAttrib (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA2E7: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F78A12: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Address 0xabaf320 is 0 bytes inside a block of size 80,048 free'd
==47968==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==47968==    by 0x4FABC31: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FADDDC: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA29F: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Block was alloc'd at
==47968==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==47968==    by 0x4FAE36C: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x14F4DF64: fill_window_dups_rev (binsearch.c:168)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==
==47968== Invalid read of size 8
==47968==    at 0x4ED66C6: Rf_getAttrib (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA2E7: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F78A12: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Address 0xabaf328 is 8 bytes inside a block of size 80,048 free'd
==47968==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==47968==    by 0x4FABC31: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FADDDC: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA29F: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Block was alloc'd at
==47968==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==47968==    by 0x4FAE36C: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x14F4DF64: fill_window_dups_rev (binsearch.c:168)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==
==47968== Invalid read of size 1
==47968==    at 0x4EEA33D: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F78A12: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x502CEC9: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Address 0xabaf320 is 0 bytes inside a block of size 80,048 free'd
==47968==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==47968==    by 0x4FABC31: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FADDDC: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA29F: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Block was alloc'd at
==47968==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==47968==    by 0x4FAE36C: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x14F4DF64: fill_window_dups_rev (binsearch.c:168)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==
==47968== Invalid read of size 1
==47968==    at 0x4EEA7A0: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F78A12: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x502CEC9: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Address 0xabaf320 is 0 bytes inside a block of size 80,048 free'd
==47968==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==47968==    by 0x4FABC31: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FADDDC: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA29F: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Block was alloc'd at
==47968==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==47968==    by 0x4FAE36C: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x14F4DF64: fill_window_dups_rev (binsearch.c:168)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==
==47968== Invalid read of size 4
==47968==    at 0x4EEA7AC: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F78A12: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x502CEC9: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Address 0xabaf350 is 48 bytes inside a block of size 80,048 free'd
==47968==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==47968==    by 0x4FABC31: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FADDDC: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA29F: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Block was alloc'd at
==47968==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==47968==    by 0x4FAE36C: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x14F4DF64: fill_window_dups_rev (binsearch.c:168)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==
==47968== Invalid read of size 1
==47968==    at 0x4EEA858: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F78A12: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x502CEC9: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Address 0xabaf320 is 0 bytes inside a block of size 80,048 free'd
==47968==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==47968==    by 0x4FABC31: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FADDDC: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4EEA29F: Rf_xlengthgets (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==  Block was alloc'd at
==47968==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==47968==    by 0x4FAE36C: Rf_allocVector3 (in /usr/lib/R/lib/libR.so)
==47968==    by 0x14F4DF64: fill_window_dups_rev (binsearch.c:168)
==47968==    by 0x4F2D29A: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F681E6: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F69643: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F7266F: Rf_eval (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4F73FD8: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2629: ??? (in /usr/lib/R/lib/libR.so)
==47968==    by 0x4FB2A8E: ??? (in /usr/lib/R/lib/libR.so)
==47968==

I think you might need to PROTECT the return value in fill_window_dups_rev. I'll make a pull request shortly which I think fixes the illegal read.

Session Info

Warning in sessionInfo() : restarting interrupted promise evaluation
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.7.0
LAPACK: /usr/lib/lapack/liblapack.so.3.7.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] xts_0.11-0 zoo_1.8-3

loaded via a namespace (and not attached):
[1] compiler_3.5.1  grid_3.5.1      lattice_0.20-35
joshuaulrich commented 6 years ago

I honestly laughed at:

Expected behavior

No segfault!

Thanks for finding and patching this.

joshuaulrich commented 6 years ago

I could pretty regularly get a segfault via:

require(xts)
ts1 <- .xts(1:100, 1:100)
ts2 <- .xts(1:200, 1:200)
i <- index(ts1)
tt <- ts2[i]

After applying:

diff --git a/R/xts.methods.R b/R/xts.methods.R
index c94ac6b..5299061 100644
--- a/R/xts.methods.R
+++ b/R/xts.methods.R
@@ -282,8 +282,9 @@ window_idx <- function(x, index. = NULL, start = NULL, end = NULL)
     # Translate from user .index to xts index
     # We get back upper bound of index as per findInterval
     tmp <- base_idx[firstlast]
-
+gctorture(TRUE)
     res <- .Call("fill_window_dups_rev", tmp, .index(x), PACKAGE = "xts")
+gctorture(FALSE)
     firstlast <- rev(res)
   }