Changeset 436


Ignore:
Timestamp:
03/07/09 12:42:23 (16 years ago)
Author:
r2d
Message:

mpccut should now be more resilient to errors

Location:
libmpc/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libmpc/trunk/libmpcdec/internal.h

    r431 r436  
    8484};
    8585
     86/**
     87 * checks if a block key is valid
     88 * @param key the two caracters key to check
     89 * @return MPC_STATUS_INVALIDSV if the key is invalid, MPC_STATUS_OK else
     90 */
     91static mpc_inline mpc_status mpc_check_key(char * key)
     92{
     93        if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90)
     94                return MPC_STATUS_INVALIDSV;
     95        return MPC_STATUS_OK;
     96}
     97
    8698/// helper functions used by multiple files
    8799mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c
  • libmpc/trunk/libmpcdec/mpc_demux.c

    r425 r436  
    112112
    113113        return (mpc_uint32_t) -1;
    114 }
    115 
    116 /**
    117  * checks if a block key is valid
    118  * @param key the two caracters key to check
    119  * @return MPC_STATUS_INVALIDSV if the key is invalid, MPC_STATUS_OK else
    120  */
    121 static mpc_inline mpc_status mpc_check_key(char * key)
    122 {
    123         if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90)
    124                 return MPC_STATUS_INVALIDSV;
    125         return MPC_STATUS_OK;
    126114}
    127115
  • libmpc/trunk/mpccut/mpccut.c

    r427 r436  
    165165
    166166        while( memcmp(b.key, "AP", 2) != 0 ) {
     167                if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
     168                        fprintf(stderr, "Error : invalid input stream\n");
     169                        goto error;
     170                }
    167171                if (memcmp(b.key, "EI", 2) == 0)
    168172                        copy_data(in_file, i, e.outputFile, b.size + size);
     
    182186
    183187        while( start_block != 0 ){
     188                if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
     189                        fprintf(stderr, "Error : invalid input stream\n");
     190                        goto error;
     191                }
    184192                if (memcmp(b.key, "AP", 2) == 0)
    185193                        start_block--;
     
    193201
    194202        while( block_num != 0 ){
     203                if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
     204                        fprintf(stderr, "Error : invalid input stream\n");
     205                        goto error;
     206                }
    195207                if (memcmp(b.key, "AP", 2) == 0) {
    196208                        if ((e.block_cnt & ((1 << e.seek_pwr) - 1)) == 0) {
     
    214226        writeBlock(&e, "SE", MPC_FALSE, 0); // write end of stream block
    215227
     228error:
    216229        fclose ( e.outputFile );
    217230        fclose ( in_file );
     
    219232        mpc_reader_exit_stdio(&reader);
    220233        mpc_encoder_exit(&e);
     234        if (err != MPC_STATUS_OK)
     235                remove(argv[optind + 1]);
    221236
    222237    return err;
Note: See TracChangeset for help on using the changeset viewer.