<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2722" name=GENERATOR><!--[if !mso]>
<STYLE>v\:* {
        BEHAVIOR: url(#default#VML)
}
o\:* {
        BEHAVIOR: url(#default#VML)
}
w\:* {
        BEHAVIOR: url(#default#VML)
}
shape {
        BEHAVIOR: url(#default#VML)
}
</STYLE>
<![endif]-->
<STYLE>
<!--
/* Font Definitions */
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=blue link=blue bgColor=#ffffff>
<DIV><FONT face=Arial size=4>Mon,</FONT></DIV>
<DIV><FONT face=Arial size=4></FONT> </DIV>
<DIV><FONT face=Arial size=4>Since the buffer check was mentioned, I will pass
on the bulk of another post which has comments interwoven with your
sample. This person admitted to not knowing Speex, but at least points out
your buffer overflow possibility and maybe something else helpful.</FONT></DIV>
<DIV><FONT face=Arial size=4></FONT> </DIV>
<DIV><FONT face=Arial size=4>Steve</FONT></DIV>
<DIV><FONT face=Arial size=4></FONT> </DIV>
<DIV>> // Program starts here:<BR>>
cout << "Starting spxdec...\n";<BR>> fo =
fopen("samp.spx","rb");<BR>><BR>> if (fo ==
NULL)<BR>> cout <<
"Error!\n";<BR><BR>if its not open why continue?<BR><BR>>
else<BR>> cout <<
"Okay!\n";<BR>><BR>> fs = fopen ("pcmfile",
"wb");<BR>><BR>> if (fs ==
NULL)<BR>> cout << "Error
creating file!\n";<BR><BR>again, why continue?<BR><BR>>
else<BR>> cout << "File
created!\n";<BR>><BR>><BR>> while
(!(feof(fo)))<BR>> {<BR>> decstate =
speex_decoder_init (&speex_nb_mode);<BR>maybe the decoder init doesn't like
getting called multiple times?<BR><BR>><BR>> // Set
default options for decoding:<BR>> temp =
1;<BR>> speex_decoder_ctl(decstate, SPEEX_SET_ENH,
&temp);<BR>maybe the decoder ctl doesn't like getting called multiple
times?<BR><BR>><BR>><BR>> // Initialize spxbits
(structure SpeexBits)<BR>> speex_bits_init
(&spxbits);<BR>maybe the bits init doesn't like getting called multiple
times?<BR><BR>><BR>><BR>>
fread (&nbBytes, sizeof(int), 1,
fo);<BR>> fread (cbits, 1, nbBytes,
fo);<BR>nbBytes could be >200 thus overflowing the buffer... all buffer sizes
should <BR>be checked before being
used.<BR><BR>><BR>> cout
<< "1"; // just to see whether the loop
iterates<BR>><BR>>
speex_bits_read_from (&spxbits, cbits,
nbBytes);<BR>> speex_decode
(decstate, &spxbits,
pcm);<BR>><BR>><BR>> // Copy
1 frame from float pcm to short
spx<BR>> for (n=0; n<FRAME_SIZE;
n++)<BR>>
spx [n] = pcm [n];<BR>><BR>>
fwrite (spx, sizeof(short), FRAME_SIZE, fs);<BR>><BR>>
}<BR>> // end of loop<BR>>
// Entire file has been read, decoded and
saved<BR>><BR>> speex_decoder_destroy
(decstate);<BR>> speex_bits_destroy
(&spxbits);<BR>> fclose (fo);<BR>>
fclose (fs);<BR>><BR>> cout << "Finished
processing!\n";<BR>> }<BR>-----------</DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=duane@counterpath.com href="mailto:duane@counterpath.com">Duane
Storey</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=mowin.dev@gmail.com
href="mailto:mowin.dev@gmail.com">'Mo Win'</A> ; <A title=speex-dev@xiph.org
href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, October 17, 2005 10:40
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> RE: [Speex-dev] Error Executing
sampledec in VC++</DIV>
<DIV><BR></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">You should really do
a check to make sure </SPAN></FONT><SPAN class=q>
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN class=q><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"><o:p> </o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal><SPAN class=q><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt">nbBytes isn’t larger than 200, otherwise you’re going
to read past the end of your char array.<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal><SPAN class=q><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"><o:p> </o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal><SPAN class=q><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt">fread (&nbBytes, sizeof(int), 1,
fo);</SPAN><o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></FONT></P>
<DIV>
<DIV class=MsoNormal style="TEXT-ALIGN: center" align=center><FONT
face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">
<HR tabIndex=-1 align=center width="100%" SIZE=2>
</SPAN></FONT></DIV>
<P class=MsoNormal><B><FONT face=Tahoma size=2><SPAN
style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT
face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"> <A
href="mailto:speex-dev-bounces@xiph.org">speex-dev-bounces@xiph.org</A>
[mailto:speex-dev-bounces@xiph.org] <B><SPAN style="FONT-WEIGHT: bold">On
Behalf Of </SPAN></B>Mo Win<BR><B><SPAN
style="FONT-WEIGHT: bold">Sent:</SPAN></B> Monday, October 17, 2005 7:31
PM<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> <A
href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</A><BR><B><SPAN
style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [Speex-dev] Error Executing
sampledec in VC++</SPAN></FONT><o:p></o:p></P></DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"><o:p> </o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 12pt"><FONT face="Times New Roman"
size=3><SPAN style="FONT-SIZE: 12pt">Hi Steve, thanks for the advice. I placed
the appropriate functions outside the while statement but I still get this
error at the while loop:<BR><BR>First-chance exception at 0x004010fa in
SPXDEC.exe: 0xC0000005: Access violation reading location
0x0000000c.<BR>Unhandled exception at 0x004010fa in SPXDEC.exe: 0xC0000005:
Access violation reading location 0x0000000c.<BR><BR>It looks like the same
error. I've attached the code below<BR><BR>Thanks,<BR>Mon<BR><BR>Portion of
the revised code:<BR><BR><BR> decstate = speex_decoder_init
(&speex_nb_mode);<BR> // Set default options for
decoding:<BR> temp = 1;<BR>
speex_decoder_ctl(decstate, SPEEX_SET_ENH,
&temp);<BR><BR> // Initialize spxbits (structure
SpeexBits)<BR> speex_bits_init
(&spxbits);<BR><BR> while
(!(feof(fo))) // this is where the problem
starts<BR> {<BR>
fread (&nbBytes, sizeof(int), 1,
fo);<BR> fread (cbits, 1, nbBytes,
fo);<BR><BR> cout << "1"; //
just to see whether the loop
iterates<BR><BR>
speex_bits_read_from (&spxbits, cbits,
nbBytes);<BR> speex_decode
(decstate, &spxbits,
pcm);<BR><BR><BR> // Copy 1 frame
from float pcm to short spx<BR> for
(n=0; n<FRAME_SIZE;
n++)<BR> spx
[n] = pcm [n];<BR><BR> fwrite (spx,
sizeof(short), FRAME_SIZE, fs);<BR><BR>
}<BR> // end of loop<BR> //
Entire file has been read, decoded and saved<BR><BR>
speex_decoder_destroy (decstate);<BR> speex_bits_destroy
(&spxbits);<BR> fclose (fo);<BR>
fclose (fs);<BR> <BR> cout << "Finished
processing!\n";<BR>}<o:p></o:p></SPAN></FONT></P>
<DIV>
<P class=MsoNormal><SPAN class=gmailquote><FONT face="Times New Roman"
size=3><SPAN style="FONT-SIZE: 12pt">On 10/18/05, <B><SPAN
style="FONT-WEIGHT: bold">Steve Russell</SPAN></B> <<A
href="mailto:srussell@innernet.net">srussell@innernet.net</A>>
wrote:</SPAN></FONT></SPAN><o:p></o:p></P>
<DIV>
<P class=MsoNormal><FONT face=Arial size=4><SPAN
style="FONT-SIZE: 13.5pt; FONT-FAMILY: Arial">Mon,</SPAN></FONT><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"> <o:p></o:p></SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal><FONT face=Arial size=4><SPAN
style="FONT-SIZE: 13.5pt; FONT-FAMILY: Arial">Here is feedback that I got
concerning the access violation, i.e. the failure of the while loop
below. Does this solve the problem?</SPAN></FONT><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"> <o:p></o:p></SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal><FONT face=Arial size=4><SPAN
style="FONT-SIZE: 13.5pt; FONT-FAMILY: Arial">Steve</SPAN></FONT><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"> <o:p></o:p></SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt">My guess is that speex_decoder_init() should be
outside the while().. loop<BR>as speex_decoder_destroy() is also
outside.<o:p></o:p></SPAN></FONT></P></DIV>
<BLOCKQUOTE
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 4pt; PADDING-BOTTOM: 0in; MARGIN: 5pt 0in 5pt 3.75pt; BORDER-LEFT: black 1.5pt solid; PADDING-TOP: 0in; BORDER-BOTTOM: medium none">
<DIV style="font-size-adjust: none; font-stretch: normal">
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">----- Original Message -----
<o:p></o:p></SPAN></FONT></P></DIV>
<DIV
style="BACKGROUND-POSITION: 0% 50%; BACKGROUND-ATTACHMENT: scroll; font-size-adjust: none; font-stretch: normal; moz-background-clip: initial; moz-background-origin: initial; moz-background-inline-policy: initial">
<P class=MsoNormal style="BACKGROUND: #e4e4e4"><B><FONT face=Arial
size=2><SPAN
style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial">From:</SPAN></FONT></B><FONT
face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> <A
title=mowin.dev@gmail.com href="mailto:mowin.dev@gmail.com" target=_blank>Mo
Win</A> <o:p></o:p></SPAN></FONT></P></DIV>
<DIV style="font-size-adjust: none; font-stretch: normal">
<P class=MsoNormal><B><FONT face=Arial size=2><SPAN
style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial">To:</SPAN></FONT></B><FONT
face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> <A
title=speex-dev@xiph.org href="mailto:speex-dev@xiph.org"
target=_blank>speex-dev@xiph.org</A> <o:p></o:p></SPAN></FONT></P></DIV>
<DIV style="font-size-adjust: none; font-stretch: normal">
<P class=MsoNormal><B><FONT face=Arial size=2><SPAN
style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial">Sent:</SPAN></FONT></B><FONT
face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> Monday,
October 17, 2005 8:05 AM<o:p></o:p></SPAN></FONT></P></DIV>
<DIV style="font-size-adjust: none; font-stretch: normal">
<P class=MsoNormal><B><FONT face=Arial size=2><SPAN
style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial">Subject:</SPAN></FONT></B><FONT
face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">
[Speex-dev] Error Executing sampledec in
VC++<o:p></o:p></SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"><o:p> </o:p></SPAN></FONT></P></DIV>
<DIV><SPAN id=q_10700a0bc525377c_2>
<P class=MsoNormal><SPAN class=q><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt">hey guys, I just compiled an application similar to
sampledec.c (for speex 1.1.10) and it was fine but when I executed it, the
app exited without doing anything. I'm using MS VC 6.0 and this was all I
got -<B><SPAN style="FONT-WEIGHT: bold"> First-chance exception in
sampledec.exe : 0xC0000005: Access Violation. </SPAN></B>Has anyone
encountered this / does anyone know how to deal with it? by the way,
sampleenc executed perfectly... </SPAN></FONT></SPAN><BR><BR><SPAN
class=q>When I removed the "while" loop in sampledec, the program executed
fine (I placed printf's to check which lines were executed). I also tried
running the loop only once (erasing only the while statement and retaining
the code within it) and it worked fine again. Something seems to be
happening during loop iteration that causes the program to terminate
abnormally.. any clues? thanks very much for any tip..</SPAN><BR><BR><SPAN
class=q>In gratitude,</SPAN><BR><SPAN class=q>Mon</SPAN><BR><BR><SPAN
class=q>(Below is my code. it's almost exactly like sampleenc except I read
a file stream instead of stdin)</SPAN><BR><BR><SPAN class=q>#include
"speex/speex.h"</SPAN><BR><BR><SPAN class=q>#include
<stdio.h></SPAN><BR><SPAN class=q>#include
<iostream.h></SPAN><BR><BR><SPAN class=q>void main ()</SPAN><BR><SPAN
class=q>{</SPAN><BR><SPAN class=q> <FONT
color=#99ff99><SPAN style="COLOR: #99ff99">//
Definitions</SPAN></FONT></SPAN><BR><SPAN class=q> #define
FRAME_SIZE 160</SPAN><BR><SPAN class=q> #define
FIXED_POINT</SPAN><BR><BR><SPAN class=q> <FONT
color=#99ff99><SPAN style="COLOR: #99ff99"> // Variable
Declarations</SPAN></FONT></SPAN><BR><SPAN class=q> FILE
*fo, *fs;</SPAN><BR><SPAN class=q> short spx
[FRAME_SIZE];</SPAN><BR><SPAN class=q> float pcm
[FRAME_SIZE];</SPAN><BR><SPAN class=q> char cbits
[200];</SPAN><BR><SPAN class=q> int nbBytes, n,
temp;</SPAN><BR><BR><SPAN class=q> void
*decstate;</SPAN><BR><SPAN class=q> SpeexBits
spxbits;</SPAN><BR><BR><BR><SPAN class=q> <FONT
color=#99ff99><SPAN style="COLOR: #99ff99">// Program starts
here:</SPAN></FONT></SPAN><BR><SPAN class=q> cout <<
"Starting spxdec...\n";</SPAN><BR><SPAN class=q> fo =
fopen("samp.spx","rb");</SPAN><BR><BR><SPAN class=q> if
(fo == NULL)</SPAN><BR><SPAN class=q>
cout << "Error!\n";</SPAN><BR><SPAN class=q>
else</SPAN><BR><SPAN class=q> cout
<< "Okay!\n";</SPAN><BR><BR><SPAN class=q> fs =
fopen ("pcmfile", "wb");</SPAN><BR><BR><SPAN class=q> if
(fs == NULL)</SPAN><BR><SPAN class=q>
cout << "Error creating file!\n";</SPAN><BR><SPAN
class=q> else</SPAN><BR><SPAN class=q>
cout << "File created!\n";</SPAN><BR><BR><BR><SPAN
class=q> while (!(feof(fo)))</SPAN><BR><SPAN
class=q> {</SPAN><BR><SPAN class=q>
decstate = speex_decoder_init (&speex_nb_mode);</SPAN><BR><BR><SPAN
class=q> // Set default options for
decoding:</SPAN><BR><SPAN class=q> temp =
1;</SPAN><BR><SPAN class=q> speex_decoder_ctl(decstate,
SPEEX_SET_ENH, &temp);</SPAN><BR><BR><BR><SPAN
class=q> // Initialize spxbits (structure
SpeexBits)</SPAN><BR><SPAN class=q> speex_bits_init
(&spxbits);</SPAN><BR><BR><BR><SPAN class=q>
fread (&nbBytes, sizeof(int), 1, fo);</SPAN><BR><SPAN
class=q> fread (cbits, 1, nbBytes,
fo);</SPAN><BR><BR><SPAN class=q> cout
<< "1"; // just to see whether the loop iterates</SPAN><BR><BR><SPAN
class=q> speex_bits_read_from
(&spxbits, cbits, nbBytes);</SPAN><BR><SPAN class=q>
speex_decode (decstate, &spxbits,
pcm);</SPAN><BR><BR><BR><SPAN class=q>
// Copy 1 frame from float pcm to short spx</SPAN><BR><SPAN
class=q> for (n=0; n<FRAME_SIZE;
n++)</SPAN><BR><SPAN class=q>
spx [n] = pcm [n];</SPAN><BR><BR><SPAN
class=q> fwrite (spx, sizeof(short),
FRAME_SIZE, fs);</SPAN><BR><BR><SPAN class=q>
}</SPAN><BR><SPAN class=q> // end of
loop</SPAN><BR><SPAN class=q> // Entire file has been
read, decoded and saved</SPAN><BR><BR><SPAN class=q>
speex_decoder_destroy (decstate);</SPAN><BR><SPAN class=q>
speex_bits_destroy (&spxbits);</SPAN><BR><SPAN
class=q> fclose (fo);</SPAN><BR><SPAN
class=q> fclose (fs);</SPAN><BR><SPAN
class=q> </SPAN><BR><SPAN class=q> cout
<< "Finished processing!\n";</SPAN><BR><SPAN
class=q>}</SPAN><BR><BR><BR><o:p></o:p></P></DIV></SPAN>
<DIV class=MsoNormal style="TEXT-ALIGN: center" align=center><SPAN
class=q><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">
<HR align=center width="100%" SIZE=2>
</SPAN></FONT></SPAN></DIV>
<P class=MsoNormal><SPAN class=q><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt">_______________________________________________</SPAN></FONT></SPAN><BR><SPAN
class=q>Speex-dev mailing list</SPAN><BR><SPAN class=q><A
href="mailto:Speex-dev@xiph.org"
target=_blank>Speex-dev@xiph.org</A></SPAN><BR><SPAN class=q><A
href="http://lists.xiph.org/mailman/listinfo/speex-dev"
target=_blank>http://lists.xiph.org/mailman/listinfo/speex-dev</A><o:p></o:p></SPAN></P></BLOCKQUOTE></DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"><o:p> </o:p></SPAN></FONT></P></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>Speex-dev mailing
list<BR>Speex-dev@xiph.org<BR>http://lists.xiph.org/mailman/listinfo/speex-dev<BR></BLOCKQUOTE></BODY></HTML>