Changeset 1248


Ignore:
Timestamp:
10/27/06 22:22:48 (7 years ago)
Author:
sam
Message:
  • Fix a buffer overflow in the utf-8 cucul_import().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/import.c

    r1245 r1248  
    407407        { 
    408408            unsigned int bytes; 
    409             /* Probably a wrong thing */ 
    410             if(((char const *)(buffer + i))[0] == 0) 
     409 
     410            if(i + 6 < size) 
     411                ch = cucul_utf8_to_utf32((char const *)(buffer + i), &bytes); 
     412            else 
    411413            { 
    412                 goto end; 
     414                /* Add a trailing zero to what we're going to read */ 
     415                char tmp[7]; 
     416                memcpy(tmp, buffer + i, size - i); 
     417                tmp[size - i] = '\0'; 
     418                ch = cucul_utf8_to_utf32(tmp, &bytes); 
    413419            } 
    414             ch = cucul_utf8_to_utf32((char const *)(buffer + i), &bytes); 
     420 
     421            if(!bytes) 
     422            { 
     423                /* If the Unicode is invalid, assume it was latin1. */ 
     424                ch = buffer[i]; 
     425                bytes = 1; 
     426            } 
    415427            wch = cucul_utf32_is_fullwidth(ch) ? 2 : 1; 
    416428            skip += bytes - 1; 
     
    445457        cucul_set_canvas_size(cv, width, height = y); 
    446458    } 
    447  end: 
     459 
    448460    return cv; 
    449461} 
Note: See TracChangeset for help on using the changeset viewer.