[Subject Prev][Subject Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hts-users:01876] bug fix in HGen.c in Calc_WUM_and_WUW


There's a small bug in HGen.c.  It should make no difference for
standard use, e.g. for the HTS demo.

In Calc_WUM_and_WUW, the range checking of each window is inconsistent
with the actual use of the window coefficients.  Specifically,
'win.width[d][WLEFT]' and 'win.width[d][WRIGHT]' should be the left and
right ends of window 'd', while the window coefficient is accessed via
'win.coef[d][-j]' rather than 'win.coef[d][j]'.  This could lead to
undefined behaviour if we access outside the bounds of the array.

Thankfully, the left and right sizes of the windows are typically the
same.  The procedure which reads in the windows from file always assigns
the same length to them for odd-length windows (the norm).  And HTS demo
can only ever use odd-length windows.  Thus under typical use the bug
will not be visible.

I noticed this while using code where the left and right window sizes
aren't the same, so I can confirm that this is the only place this
problem seems to occur.

Please see attached patch-like diff.

Thanks,

Matt Shannon
hunk ./HTKLib/HGen.c 1096
-                  if ((t+j>0) && (t+j<=pst->T)) {
+                  if ((t-j>0) && (t-j<=pst->T)) {
hunk ./HTKLib/HGen.c 1098
-                     if ((n==1) && (pst->win.width[d][WLEFT]<=j) && (j<=pst->win.width[d][WRIGHT]) && (pst->win.coef[d][-j]!=0.0))
-                        pst->WUM[M*(t-1)+m] += ((double)pst->win.coef[d][-j]) * pst->mseq[t+j][d*pst->order+m+bias];
+                     if ((n==1) && (pst->win.width[d][WLEFT]<=j) && (j<=pst->win.width[d][WRIGHT]) && (pst->win.coef[d][j]!=0.0))
+                        pst->WUM[M*(t-1)+m] += ((double)pst->win.coef[d][j]) * pst->mseq[t-j][d*pst->order+m+bias];
hunk ./HTKLib/HGen.c 1104
-                        cov = (!full) ? pst->vseq[t+j].var[pst->order*l+m+bias] :
-                              ((pst->order*l+m > pst->order*d+n) ? pst->vseq[t+j].inv[pst->order*l+m][pst->order*d+n]
-                                                                 : pst->vseq[t+j].inv[pst->order*d+n][pst->order*l+m]);
+                        cov = (!full) ? pst->vseq[t-j].var[pst->order*l+m+bias] :
+                              ((pst->order*l+m > pst->order*d+n) ? pst->vseq[t-j].inv[pst->order*l+m][pst->order*d+n]
+                                                                 : pst->vseq[t-j].inv[pst->order*d+n][pst->order*l+m]);
hunk ./HTKLib/HGen.c 1108
-                        if (cov!=0.0 && pst->win.width[l][WLEFT] <=j && j<=pst->win.width[l][WRIGHT] && pst->win.coef[l][-j]!=0.0)
-                           WU += cov * (double)pst->win.coef[l][-j];
+                        if (cov!=0.0 && pst->win.width[l][WLEFT]<=j && j<=pst->win.width[l][WRIGHT] && pst->win.coef[l][j]!=0.0)
+                           WU += cov * (double)pst->win.coef[l][j];
hunk ./HTKLib/HGen.c 1114
-                        if ((pst->win.width[d][WLEFT]<=k-j) && (k-j<=pst->win.width[d][WRIGHT]) && (M*k+n-m+1>0) && (pst->win.coef[d][k-j]!=0.0))
-                           pst->WUW[M*(t-1)+m][M*k+n-m+1] += WU*(double)pst->win.coef[d][k-j];
+                        if ((pst->win.width[d][WLEFT]<=k+j) && (k+j<=pst->win.width[d][WRIGHT]) && (M*k+n-m+1>0) && (pst->win.coef[d][k+j]!=0.0))
+                           pst->WUW[M*(t-1)+m][M*k+n-m+1] += WU*(double)pst->win.coef[d][k+j];

Follow-Ups
[hts-users:01877] Re: bug fix in HGen.c in Calc_WUM_and_WUW, Heiga Zen (Byung Ha CHUN)