> From: "Sigbjxrn Skjfret" <[EMAIL PROTECTED]>
> 
> Something is wrong again, as I now am experiencing random crashes again, this
> has been long gone, but somewhere around 3.30-3.50 it has been reintroduced. :(
> 
> I'm not sure, but I believe the previous problem was due to buffer overflow or
> some dodgy memory allocation .. if anyone could check this out, it'd be gr8. ;)
> 
> 
> - CISC
> 

I got one other report of strange crashes also.  

One quick thing I can think of is some code that was changed
in l3bitstream.c.  Ben Jacobs noticed that the original ISO
code was allocating more memory than
the size of the object.  He cautioned against "fixing" this because
you never know what kind of sloppy coding was being used, but
I went ahead and fixed it anyway.  (and now that I look at
what I did - I forgot to initialize the structs to 0)

Can you try out the replacement subroutine below?

Mark



Replacement III_format_bitstream, in l3bitstream.c:


void
III_format_bitstream( int              bitsPerFrame,
                      frame_params     *in_fr_ps,
                      int              l3_enc[2][2][576],
                      III_side_info_t  *l3_side,
                      III_scalefac_t   *scalefac,
                      Bit_stream_struc *in_bs,
                      double           (*xr)[2][576],
                      char             *ancillary,
                      int              ancillary_bits )
{
    int gr, ch,  mode_gr;
#if 0
    static BF_FrameData real_frameData;
    static BF_FrameResults real_frameResults;
    frameData = &real_frameData;
    frameResults = &real_frameResults;
#endif

    fr_ps = in_fr_ps;
    bs = in_bs;
    stereo = fr_ps->stereo;
    mode_gr = (fr_ps->header->version == 1) ? 2 : 1;


    /* sizeof(*frameData) = 100 */
    /* sizeof(*frameResults) = 12 */
    if ( frameData == NULL )
    {
        frameData = (BF_FrameData*) calloc( 1, sizeof(BF_FrameData) );
        assert( frameData );
    }
    if ( frameResults == NULL )
    {
        frameResults = (BF_FrameResults*) calloc( 1, sizeof(BF_FrameData) );
        assert( frameData );
    }

    if ( !PartHoldersInitialized )
    {
        headerPH = BF_newPartHolder( 12 );
        frameSIPH = BF_newPartHolder( 12 );

        for ( ch = 0; ch < MAX_CHANNELS; ch++ )
            channelSIPH[ch] = BF_newPartHolder( 8 );

        for ( gr = 0; gr < MAX_GRANULES; gr++ ) 
            for ( ch = 0; ch < MAX_CHANNELS; ch++ )
            {
                spectrumSIPH[gr][ch]   = BF_newPartHolder( 32 );
                scaleFactorsPH[gr][ch] = BF_newPartHolder( 64 );
                codedDataPH[gr][ch]    = BF_newPartHolder( 576 );
                userSpectrumPH[gr][ch] = BF_newPartHolder( 4 );
            }
        userFrameDataPH = BF_newPartHolder( 8 );
        PartHoldersInitialized = 1;
    }

#if 0
    /* this makes more sense in loop.c */
    for ( gr = 0; gr < mode_gr; gr++ )
        for ( ch =  0; ch < stereo; ch++ )
        {
            int *pi = &l3_enc[gr][ch][0];
            int i;
            for ( i = 0; i < 576; i++)      {
              double pr = xr[gr][ch][i];
              /* ms stereo fix.  if ms_stereo, l3_enc will be M/S values */
              if (in_fr_ps->header->mode_ext == 2) {
                pr = ch ? (xr[gr][0][i]-xr[gr][1][i]) : (xr[gr][0][i]+xr[gr][1][i]);
                /* pr /= sqrt(2.0); */
              }

              if ( (pr < 0) && (pi[i] > 0) )   pi[i] *= -1;
            }
        }
#endif

    encodeSideInfo( l3_side );
    encodeMainData( l3_enc, l3_side, scalefac );
    write_ancillary_data( ancillary, ancillary_bits );



    if ( l3_side->resvDrain )
        drain_into_ancillary_data( l3_side->resvDrain );
    /*
      Put frameData together for the call
      to BitstreamFrame()
    */
    frameData->putbits     = putMyBits;
    frameData->frameLength = bitsPerFrame;
    frameData->nGranules   = mode_gr;
    frameData->nChannels   = stereo;
    frameData->header      = headerPH->part;
    frameData->frameSI     = frameSIPH->part;

    for ( ch = 0; ch < stereo; ch++ )
        frameData->channelSI[ch] = channelSIPH[ch]->part;

    for ( gr = 0; gr < mode_gr; gr++ )
        for ( ch = 0; ch < stereo; ch++ )
        {
            frameData->spectrumSI[gr][ch]   = spectrumSIPH[gr][ch]->part;
            frameData->scaleFactors[gr][ch] = scaleFactorsPH[gr][ch]->part;
            frameData->codedData[gr][ch]    = codedDataPH[gr][ch]->part;
            frameData->userSpectrum[gr][ch] = userSpectrumPH[gr][ch]->part;
        }
    frameData->userFrameData = userFrameDataPH->part;

    BF_BitstreamFrame( frameData, frameResults );

    /* we set this here -- it will be tested in the next loops iteration */
    l3_side->main_data_begin = frameResults->nextBackPtr;

}








Replacement III_format_bitstream, in l3bitstream.c:


void
III_format_bitstream( int              bitsPerFrame,
                      frame_params     *in_fr_ps,
                      int              l3_enc[2][2][576],
                      III_side_info_t  *l3_side,
                      III_scalefac_t   *scalefac,
                      Bit_stream_struc *in_bs,
                      double           (*xr)[2][576],
                      char             *ancillary,
                      int              ancillary_bits )
{
    int gr, ch,  mode_gr;
#if 0
    static BF_FrameData real_frameData;
    static BF_FrameResults real_frameResults;
    frameData = &real_frameData;
    frameResults = &real_frameResults;
#endif

    fr_ps = in_fr_ps;
    bs = in_bs;
    stereo = fr_ps->stereo;
    mode_gr = (fr_ps->header->version == 1) ? 2 : 1;


    /* sizeof(*frameData) = 100 */
    /* sizeof(*frameResults) = 12 */
    if ( frameData == NULL )
    {
        frameData = (BF_FrameData*) calloc( 1, sizeof(BF_FrameData) );
        assert( frameData );
    }
    if ( frameResults == NULL )
    {
        frameResults = (BF_FrameResults*) calloc( 1, sizeof(BF_FrameData) );
        assert( frameData );
    }

    if ( !PartHoldersInitialized )
    {
        headerPH = BF_newPartHolder( 12 );
        frameSIPH = BF_newPartHolder( 12 );

        for ( ch = 0; ch < MAX_CHANNELS; ch++ )
            channelSIPH[ch] = BF_newPartHolder( 8 );

        for ( gr = 0; gr < MAX_GRANULES; gr++ ) 
            for ( ch = 0; ch < MAX_CHANNELS; ch++ )
            {
                spectrumSIPH[gr][ch]   = BF_newPartHolder( 32 );
                scaleFactorsPH[gr][ch] = BF_newPartHolder( 64 );
                codedDataPH[gr][ch]    = BF_newPartHolder( 576 );
                userSpectrumPH[gr][ch] = BF_newPartHolder( 4 );
            }
        userFrameDataPH = BF_newPartHolder( 8 );
        PartHoldersInitialized = 1;
    }

#if 0
    /* this makes more sense in loop.c */
    for ( gr = 0; gr < mode_gr; gr++ )
        for ( ch =  0; ch < stereo; ch++ )
        {
            int *pi = &l3_enc[gr][ch][0];
            int i;
            for ( i = 0; i < 576; i++)      {
              double pr = xr[gr][ch][i];
              /* ms stereo fix.  if ms_stereo, l3_enc will be M/S values */
              if (in_fr_ps->header->mode_ext == 2) {
                pr = ch ? (xr[gr][0][i]-xr[gr][1][i]) : (xr[gr][0][i]+xr[gr][1][i]);
                /* pr /= sqrt(2.0); */
              }

              if ( (pr < 0) && (pi[i] > 0) )   pi[i] *= -1;
            }
        }
#endif

    encodeSideInfo( l3_side );
    encodeMainData( l3_enc, l3_side, scalefac );
    write_ancillary_data( ancillary, ancillary_bits );



    if ( l3_side->resvDrain )
        drain_into_ancillary_data( l3_side->resvDrain );
    /*
      Put frameData together for the call
      to BitstreamFrame()
    */
    frameData->putbits     = putMyBits;
    frameData->frameLength = bitsPerFrame;
    frameData->nGranules   = mode_gr;
    frameData->nChannels   = stereo;
    frameData->header      = headerPH->part;
    frameData->frameSI     = frameSIPH->part;

    for ( ch = 0; ch < stereo; ch++ )
        frameData->channelSI[ch] = channelSIPH[ch]->part;

    for ( gr = 0; gr < mode_gr; gr++ )
        for ( ch = 0; ch < stereo; ch++ )
        {
            frameData->spectrumSI[gr][ch]   = spectrumSIPH[gr][ch]->part;
            frameData->scaleFactors[gr][ch] = scaleFactorsPH[gr][ch]->part;
            frameData->codedData[gr][ch]    = codedDataPH[gr][ch]->part;
            frameData->userSpectrum[gr][ch] = userSpectrumPH[gr][ch]->part;
        }
    frameData->userFrameData = userFrameDataPH->part;

    BF_BitstreamFrame( frameData, frameResults );

    /* we set this here -- it will be tested in the next loops iteration */
    l3_side->main_data_begin = frameResults->nextBackPtr;

}
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to