[XviD-devel] Floating point exception in xvid_decore()

Chris Watt cnww at hfx.andara.com
Tue Jun 26 02:22:49 CEST 2007


In my application linked against libxvidcore 1.1.2, calling
xvid_decore() sometimes causes a "Floating point exception" resulting in
a core dump. I have included an ugly, but fairly portable workaround
below for the next person searching the list archives.

I am using a simple decoder loop based on the example in xvid_decraw.c,
fed data parsed out of an Ogg stream. About 5-10% of the time after an
error in the input stream the next call to xvid_decraw() results in a
floating point exception (SIGFPE).

I'm not sure if this is a bug in Xvid or incorrect usage. My program
currently responds to an error or gap in the bitstream (e.g. because we
missed part of a live Ogg stream) by resuming calls to xvid_decore()
with the payload of the first valid Ogg packet after the error. Is there
a better way to way to handle a known error in the input bitstream?

Any suggestions would be helpful.

My current workaround is:

--- cut here ---

static sigjmp_buf pre_decore_env;
static void handlefpe( int sig, siginfo_t *siginfo, void* opaque );

int decode_xvid(...)
{
...
    struct sigaction act, oldact;
    memset( &act, 0, sizeof( struct sigaction ));
    act.sa_flags = SA_SIGINFO;
    act.sa_sigaction = handlefpe;
    assert( sigaction( SIGFPE, &act, &oldact ) == 0 );

    if( sigsetjmp(pre_decore_env, 1) == 0 ) //See handlefpe()
    {
        bytes_used = xvid_decore(...);
    }
    else
    {
        //Make sure the state changes before calling xvid_decore again
or we'll cause the same exception
        bytes_used = 1;
    }

    assert( sigaction( SIGFPE, &oldact, &act ) == 0 ); //This statement
has no effect?
...
}

static void handlefpe( int sig, siginfo_t *siginfo, void* opaque )
{
    tprintf( "decode_xvid(): WARNING: Xvid decoder threw SIGFPE
again.\n", sig );
    feclearexcept(FE_ALL_EXCEPT);
    siglongjmp(pre_decore_env, 1 ); //Jump back before xvid_decore() and
take the other branch
}

--- cut here ---


More information about the XviD-devel mailing list