idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
5,500
smp_fetch_url_param(const struct arg *args, struct sample *smp, const char *kw, void *private) { struct http_msg *msg; char delim = '?'; const char *name; int name_len; if (!args || (args[0].type && args[0].type != ARGT_STR) || (args[1].type && args[1].type != ARGT_STR)) return 0; name = ""; name_len = 0; if (args->type == ARGT_STR) { name = args->data.str.str; name_len = args->data.str.len; } if (args[1].type) delim = *args[1].data.str.str; if (!smp->ctx.a[0]) { // first call, find the query string CHECK_HTTP_MESSAGE_FIRST(); msg = &smp->strm->txn->req; smp->ctx.a[0] = find_param_list(msg->chn->buf->p + msg->sl.rq.u, msg->sl.rq.u_l, delim); if (!smp->ctx.a[0]) return 0; smp->ctx.a[1] = msg->chn->buf->p + msg->sl.rq.u + msg->sl.rq.u_l; /* Assume that the context is filled with NULL pointer * before the first call. * smp->ctx.a[2] = NULL; * smp->ctx.a[3] = NULL; */ } return smp_fetch_param(delim, name, name_len, args, smp, kw, private); }
+Info
0
smp_fetch_url_param(const struct arg *args, struct sample *smp, const char *kw, void *private) { struct http_msg *msg; char delim = '?'; const char *name; int name_len; if (!args || (args[0].type && args[0].type != ARGT_STR) || (args[1].type && args[1].type != ARGT_STR)) return 0; name = ""; name_len = 0; if (args->type == ARGT_STR) { name = args->data.str.str; name_len = args->data.str.len; } if (args[1].type) delim = *args[1].data.str.str; if (!smp->ctx.a[0]) { // first call, find the query string CHECK_HTTP_MESSAGE_FIRST(); msg = &smp->strm->txn->req; smp->ctx.a[0] = find_param_list(msg->chn->buf->p + msg->sl.rq.u, msg->sl.rq.u_l, delim); if (!smp->ctx.a[0]) return 0; smp->ctx.a[1] = msg->chn->buf->p + msg->sl.rq.u + msg->sl.rq.u_l; /* Assume that the context is filled with NULL pointer * before the first call. * smp->ctx.a[2] = NULL; * smp->ctx.a[3] = NULL; */ } return smp_fetch_param(delim, name, name_len, args, smp, kw, private); }
@@ -7724,6 +7724,15 @@ void check_request_for_cacheability(struct stream *s, struct channel *chn) } } + /* Don't use the cache and don't try to store if we found the + * Authorization header */ + val = http_header_match2(cur_ptr, cur_end, "Authorization", 13); + if (val) { + txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK; + txn->flags |= TX_CACHE_IGNORE; + continue; + } + val = http_header_match2(cur_ptr, cur_end, "Cache-control", 13); if (!val) continue;
CWE-200
null
null
5,501
smp_fetch_url_param_val(const struct arg *args, struct sample *smp, const char *kw, void *private) { int ret = smp_fetch_url_param(args, smp, kw, private); if (ret > 0) { smp->data.type = SMP_T_SINT; smp->data.u.sint = strl2ic(smp->data.u.str.str, smp->data.u.str.len); } return ret; }
+Info
0
smp_fetch_url_param_val(const struct arg *args, struct sample *smp, const char *kw, void *private) { int ret = smp_fetch_url_param(args, smp, kw, private); if (ret > 0) { smp->data.type = SMP_T_SINT; smp->data.u.sint = strl2ic(smp->data.u.str.str, smp->data.u.str.len); } return ret; }
@@ -7724,6 +7724,15 @@ void check_request_for_cacheability(struct stream *s, struct channel *chn) } } + /* Don't use the cache and don't try to store if we found the + * Authorization header */ + val = http_header_match2(cur_ptr, cur_end, "Authorization", 13); + if (val) { + txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK; + txn->flags |= TX_CACHE_IGNORE; + continue; + } + val = http_header_match2(cur_ptr, cur_end, "Cache-control", 13); if (!val) continue;
CWE-200
null
null
5,502
smp_fetch_url_port(const struct arg *args, struct sample *smp, const char *kw, void *private) { struct http_txn *txn; struct sockaddr_storage addr; CHECK_HTTP_MESSAGE_FIRST(); txn = smp->strm->txn; url2sa(txn->req.chn->buf->p + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &addr, NULL); if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) return 0; smp->data.type = SMP_T_SINT; smp->data.u.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port); smp->flags = 0; return 1; }
+Info
0
smp_fetch_url_port(const struct arg *args, struct sample *smp, const char *kw, void *private) { struct http_txn *txn; struct sockaddr_storage addr; CHECK_HTTP_MESSAGE_FIRST(); txn = smp->strm->txn; url2sa(txn->req.chn->buf->p + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &addr, NULL); if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) return 0; smp->data.type = SMP_T_SINT; smp->data.u.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port); smp->flags = 0; return 1; }
@@ -7724,6 +7724,15 @@ void check_request_for_cacheability(struct stream *s, struct channel *chn) } } + /* Don't use the cache and don't try to store if we found the + * Authorization header */ + val = http_header_match2(cur_ptr, cur_end, "Authorization", 13); + if (val) { + txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK; + txn->flags |= TX_CACHE_IGNORE; + continue; + } + val = http_header_match2(cur_ptr, cur_end, "Cache-control", 13); if (!val) continue;
CWE-200
null
null
5,503
int smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt, const struct arg *args, struct sample *smp, int req_vol) { struct http_txn *txn; struct http_msg *msg; /* Note: it is possible that <s> is NULL when called before stream * initialization (eg: tcp-request connection), so this function is the * one responsible for guarding against this case for all HTTP users. */ if (!s) return 0; if (!s->txn) { if (unlikely(!http_alloc_txn(s))) return 0; /* not enough memory */ http_init_txn(s); } txn = s->txn; msg = &txn->req; /* Check for a dependency on a request */ smp->data.type = SMP_T_BOOL; if ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ) { /* If the buffer does not leave enough free space at the end, * we must first realign it. */ if (s->req.buf->p > s->req.buf->data && s->req.buf->i + s->req.buf->p > s->req.buf->data + s->req.buf->size - global.tune.maxrewrite) buffer_slow_realign(s->req.buf); if (unlikely(txn->req.msg_state < HTTP_MSG_BODY)) { if (msg->msg_state == HTTP_MSG_ERROR) return 0; /* Try to decode HTTP request */ if (likely(msg->next < s->req.buf->i)) http_msg_analyzer(msg, &txn->hdr_idx); /* Still no valid request ? */ if (unlikely(msg->msg_state < HTTP_MSG_BODY)) { if ((msg->msg_state == HTTP_MSG_ERROR) || buffer_full(s->req.buf, global.tune.maxrewrite)) { return 0; } /* wait for final state */ smp->flags |= SMP_F_MAY_CHANGE; return 0; } /* OK we just got a valid HTTP request. We have some minor * preparation to perform so that further checks can rely * on HTTP tests. */ /* If the request was parsed but was too large, we must absolutely * return an error so that it is not processed. At the moment this * cannot happen, but if the parsers are to change in the future, * we want this check to be maintained. */ if (unlikely(s->req.buf->i + s->req.buf->p > s->req.buf->data + s->req.buf->size - global.tune.maxrewrite)) { msg->err_state = msg->msg_state; msg->msg_state = HTTP_MSG_ERROR; smp->data.u.sint = 1; return 1; } txn->meth = find_http_meth(msg->chn->buf->p, msg->sl.rq.m_l); if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD) s->flags |= SF_REDIRECTABLE; if (unlikely(msg->sl.rq.v_l == 0) && !http_upgrade_v09_to_v10(txn)) return 0; } if (req_vol && txn->rsp.msg_state != HTTP_MSG_RPBEFORE) { return 0; /* data might have moved and indexes changed */ } /* otherwise everything's ready for the request */ } else { /* Check for a dependency on a response */ if (txn->rsp.msg_state < HTTP_MSG_BODY) { smp->flags |= SMP_F_MAY_CHANGE; return 0; } } /* everything's OK */ smp->data.u.sint = 1; return 1; }
+Info
0
int smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt, const struct arg *args, struct sample *smp, int req_vol) { struct http_txn *txn; struct http_msg *msg; /* Note: it is possible that <s> is NULL when called before stream * initialization (eg: tcp-request connection), so this function is the * one responsible for guarding against this case for all HTTP users. */ if (!s) return 0; if (!s->txn) { if (unlikely(!http_alloc_txn(s))) return 0; /* not enough memory */ http_init_txn(s); } txn = s->txn; msg = &txn->req; /* Check for a dependency on a request */ smp->data.type = SMP_T_BOOL; if ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ) { /* If the buffer does not leave enough free space at the end, * we must first realign it. */ if (s->req.buf->p > s->req.buf->data && s->req.buf->i + s->req.buf->p > s->req.buf->data + s->req.buf->size - global.tune.maxrewrite) buffer_slow_realign(s->req.buf); if (unlikely(txn->req.msg_state < HTTP_MSG_BODY)) { if (msg->msg_state == HTTP_MSG_ERROR) return 0; /* Try to decode HTTP request */ if (likely(msg->next < s->req.buf->i)) http_msg_analyzer(msg, &txn->hdr_idx); /* Still no valid request ? */ if (unlikely(msg->msg_state < HTTP_MSG_BODY)) { if ((msg->msg_state == HTTP_MSG_ERROR) || buffer_full(s->req.buf, global.tune.maxrewrite)) { return 0; } /* wait for final state */ smp->flags |= SMP_F_MAY_CHANGE; return 0; } /* OK we just got a valid HTTP request. We have some minor * preparation to perform so that further checks can rely * on HTTP tests. */ /* If the request was parsed but was too large, we must absolutely * return an error so that it is not processed. At the moment this * cannot happen, but if the parsers are to change in the future, * we want this check to be maintained. */ if (unlikely(s->req.buf->i + s->req.buf->p > s->req.buf->data + s->req.buf->size - global.tune.maxrewrite)) { msg->err_state = msg->msg_state; msg->msg_state = HTTP_MSG_ERROR; smp->data.u.sint = 1; return 1; } txn->meth = find_http_meth(msg->chn->buf->p, msg->sl.rq.m_l); if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD) s->flags |= SF_REDIRECTABLE; if (unlikely(msg->sl.rq.v_l == 0) && !http_upgrade_v09_to_v10(txn)) return 0; } if (req_vol && txn->rsp.msg_state != HTTP_MSG_RPBEFORE) { return 0; /* data might have moved and indexes changed */ } /* otherwise everything's ready for the request */ } else { /* Check for a dependency on a response */ if (txn->rsp.msg_state < HTTP_MSG_BODY) { smp->flags |= SMP_F_MAY_CHANGE; return 0; } } /* everything's OK */ smp->data.u.sint = 1; return 1; }
@@ -7724,6 +7724,15 @@ void check_request_for_cacheability(struct stream *s, struct channel *chn) } } + /* Don't use the cache and don't try to store if we found the + * Authorization header */ + val = http_header_match2(cur_ptr, cur_end, "Authorization", 13); + if (val) { + txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK; + txn->flags |= TX_CACHE_IGNORE; + continue; + } + val = http_header_match2(cur_ptr, cur_end, "Cache-control", 13); if (!val) continue;
CWE-200
null
null
5,504
int stats_check_uri(struct stream_interface *si, struct http_txn *txn, struct proxy *backend) { struct uri_auth *uri_auth = backend->uri_auth; struct http_msg *msg = &txn->req; const char *uri = msg->chn->buf->p+ msg->sl.rq.u; if (!uri_auth) return 0; if (txn->meth != HTTP_METH_GET && txn->meth != HTTP_METH_HEAD && txn->meth != HTTP_METH_POST) return 0; /* check URI size */ if (uri_auth->uri_len > msg->sl.rq.u_l) return 0; if (memcmp(uri, uri_auth->uri_prefix, uri_auth->uri_len) != 0) return 0; return 1; }
+Info
0
int stats_check_uri(struct stream_interface *si, struct http_txn *txn, struct proxy *backend) { struct uri_auth *uri_auth = backend->uri_auth; struct http_msg *msg = &txn->req; const char *uri = msg->chn->buf->p+ msg->sl.rq.u; if (!uri_auth) return 0; if (txn->meth != HTTP_METH_GET && txn->meth != HTTP_METH_HEAD && txn->meth != HTTP_METH_POST) return 0; /* check URI size */ if (uri_auth->uri_len > msg->sl.rq.u_l) return 0; if (memcmp(uri, uri_auth->uri_prefix, uri_auth->uri_len) != 0) return 0; return 1; }
@@ -7724,6 +7724,15 @@ void check_request_for_cacheability(struct stream *s, struct channel *chn) } } + /* Don't use the cache and don't try to store if we found the + * Authorization header */ + val = http_header_match2(cur_ptr, cur_end, "Authorization", 13); + if (val) { + txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK; + txn->flags |= TX_CACHE_IGNORE; + continue; + } + val = http_header_match2(cur_ptr, cur_end, "Cache-control", 13); if (!val) continue;
CWE-200
null
null
5,505
int val_hdr(struct arg *arg, char **err_msg) { if (arg && arg[1].type == ARGT_SINT && arg[1].data.sint < -MAX_HDR_HISTORY) { memprintf(err_msg, "header occurrence must be >= %d", -MAX_HDR_HISTORY); return 0; } return 1; }
+Info
0
int val_hdr(struct arg *arg, char **err_msg) { if (arg && arg[1].type == ARGT_SINT && arg[1].data.sint < -MAX_HDR_HISTORY) { memprintf(err_msg, "header occurrence must be >= %d", -MAX_HDR_HISTORY); return 0; } return 1; }
@@ -7724,6 +7724,15 @@ void check_request_for_cacheability(struct stream *s, struct channel *chn) } } + /* Don't use the cache and don't try to store if we found the + * Authorization header */ + val = http_header_match2(cur_ptr, cur_end, "Authorization", 13); + if (val) { + txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK; + txn->flags |= TX_CACHE_IGNORE; + continue; + } + val = http_header_match2(cur_ptr, cur_end, "Cache-control", 13); if (!val) continue;
CWE-200
null
null
5,506
FT_Stream_New( FT_Library library, const FT_Open_Args* args, FT_Stream *astream ) { FT_Error error; FT_Memory memory; FT_Stream stream = NULL; *astream = 0; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !args ) return FT_THROW( Invalid_Argument ); memory = library->memory; if ( FT_NEW( stream ) ) goto Exit; stream->memory = memory; if ( args->flags & FT_OPEN_MEMORY ) { /* create a memory-based stream */ FT_Stream_OpenMemory( stream, (const FT_Byte*)args->memory_base, args->memory_size ); } #ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT else if ( args->flags & FT_OPEN_PATHNAME ) { /* create a normal system stream */ error = FT_Stream_Open( stream, args->pathname ); stream->pathname.pointer = args->pathname; } else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream ) { /* use an existing, user-provided stream */ /* in this case, we do not need to allocate a new stream object */ /* since the caller is responsible for closing it himself */ FT_FREE( stream ); stream = args->stream; } #endif else error = FT_THROW( Invalid_Argument ); if ( error ) FT_FREE( stream ); else stream->memory = memory; /* just to be certain */ *astream = stream; Exit: return error; }
DoS Overflow
0
FT_Stream_New( FT_Library library, const FT_Open_Args* args, FT_Stream *astream ) { FT_Error error; FT_Memory memory; FT_Stream stream = NULL; *astream = 0; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !args ) return FT_THROW( Invalid_Argument ); memory = library->memory; if ( FT_NEW( stream ) ) goto Exit; stream->memory = memory; if ( args->flags & FT_OPEN_MEMORY ) { /* create a memory-based stream */ FT_Stream_OpenMemory( stream, (const FT_Byte*)args->memory_base, args->memory_size ); } #ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT else if ( args->flags & FT_OPEN_PATHNAME ) { /* create a normal system stream */ error = FT_Stream_Open( stream, args->pathname ); stream->pathname.pointer = args->pathname; } else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream ) { /* use an existing, user-provided stream */ /* in this case, we do not need to allocate a new stream object */ /* since the caller is responsible for closing it himself */ FT_FREE( stream ); stream = args->stream; } #endif else error = FT_THROW( Invalid_Argument ); if ( error ) FT_FREE( stream ); else stream->memory = memory; /* just to be certain */ *astream = stream; Exit: return error; }
@@ -1586,8 +1586,10 @@ */ FT_TRACE4(( " POST fragment #%d: length=0x%08x\n", i, temp)); - if ( 0x7FFFFFFFUL < temp ) + if ( 0x7FFFFFFFUL < temp || pfb_len + temp + 6 < pfb_len ) { + FT_TRACE2(( " too long fragment length makes" + " pfb_len confused: temp=0x%08x\n", temp )); error = FT_THROW( Invalid_Offset ); goto Exit; } @@ -1600,8 +1602,7 @@ resource_cnt, pfb_len + 2)); if ( pfb_len + 2 < 6 ) { FT_TRACE2(( " too long fragment length makes" - " pfb_len confused: 0x%08x\n", - pfb_len )); + " pfb_len confused: pfb_len=0x%08x\n", pfb_len )); error = FT_THROW( Array_Too_Large ); goto Exit; }
null
null
null
5,507
ft_service_list_lookup( FT_ServiceDesc service_descriptors, const char* service_id ) { FT_Pointer result = NULL; FT_ServiceDesc desc = service_descriptors; if ( desc && service_id ) { for ( ; desc->serv_id != NULL; desc++ ) { if ( ft_strcmp( desc->serv_id, service_id ) == 0 ) { result = (FT_Pointer)desc->serv_data; break; } } } return result; }
DoS Overflow
0
ft_service_list_lookup( FT_ServiceDesc service_descriptors, const char* service_id ) { FT_Pointer result = NULL; FT_ServiceDesc desc = service_descriptors; if ( desc && service_id ) { for ( ; desc->serv_id != NULL; desc++ ) { if ( ft_strcmp( desc->serv_id, service_id ) == 0 ) { result = (FT_Pointer)desc->serv_data; break; } } } return result; }
@@ -1586,8 +1586,10 @@ */ FT_TRACE4(( " POST fragment #%d: length=0x%08x\n", i, temp)); - if ( 0x7FFFFFFFUL < temp ) + if ( 0x7FFFFFFFUL < temp || pfb_len + temp + 6 < pfb_len ) { + FT_TRACE2(( " too long fragment length makes" + " pfb_len confused: temp=0x%08x\n", temp )); error = FT_THROW( Invalid_Offset ); goto Exit; } @@ -1600,8 +1602,7 @@ resource_cnt, pfb_len + 2)); if ( pfb_len + 2 < 6 ) { FT_TRACE2(( " too long fragment length makes" - " pfb_len confused: 0x%08x\n", - pfb_len )); + " pfb_len confused: pfb_len=0x%08x\n", pfb_len )); error = FT_THROW( Array_Too_Large ); goto Exit; }
null
null
null
5,508
ft_validator_init( FT_Validator valid, const FT_Byte* base, const FT_Byte* limit, FT_ValidationLevel level ) { valid->base = base; valid->limit = limit; valid->level = level; valid->error = FT_Err_Ok; }
DoS Overflow
0
ft_validator_init( FT_Validator valid, const FT_Byte* base, const FT_Byte* limit, FT_ValidationLevel level ) { valid->base = base; valid->limit = limit; valid->level = level; valid->error = FT_Err_Ok; }
@@ -1586,8 +1586,10 @@ */ FT_TRACE4(( " POST fragment #%d: length=0x%08x\n", i, temp)); - if ( 0x7FFFFFFFUL < temp ) + if ( 0x7FFFFFFFUL < temp || pfb_len + temp + 6 < pfb_len ) { + FT_TRACE2(( " too long fragment length makes" + " pfb_len confused: temp=0x%08x\n", temp )); error = FT_THROW( Invalid_Offset ); goto Exit; } @@ -1600,8 +1602,7 @@ resource_cnt, pfb_len + 2)); if ( pfb_len + 2 < 6 ) { FT_TRACE2(( " too long fragment length makes" - " pfb_len confused: 0x%08x\n", - pfb_len )); + " pfb_len confused: pfb_len=0x%08x\n", pfb_len )); error = FT_THROW( Array_Too_Large ); goto Exit; }
null
null
null
5,509
ft_validator_run( FT_Validator valid ) { /* This function doesn't work! None should call it. */ FT_UNUSED( valid ); return -1; }
DoS Overflow
0
ft_validator_run( FT_Validator valid ) { /* This function doesn't work! None should call it. */ FT_UNUSED( valid ); return -1; }
@@ -1586,8 +1586,10 @@ */ FT_TRACE4(( " POST fragment #%d: length=0x%08x\n", i, temp)); - if ( 0x7FFFFFFFUL < temp ) + if ( 0x7FFFFFFFUL < temp || pfb_len + temp + 6 < pfb_len ) { + FT_TRACE2(( " too long fragment length makes" + " pfb_len confused: temp=0x%08x\n", temp )); error = FT_THROW( Invalid_Offset ); goto Exit; } @@ -1600,8 +1602,7 @@ resource_cnt, pfb_len + 2)); if ( pfb_len + 2 < 6 ) { FT_TRACE2(( " too long fragment length makes" - " pfb_len confused: 0x%08x\n", - pfb_len )); + " pfb_len confused: pfb_len=0x%08x\n", pfb_len )); error = FT_THROW( Array_Too_Large ); goto Exit; }
null
null
null
5,510
FT_ATSFontGetFileReference( ATSFontRef ats_font_id, FSRef* ats_font_ref ) { #if defined( MAC_OS_X_VERSION_10_5 ) && \ ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) OSStatus err; err = ATSFontGetFileReference( ats_font_id, ats_font_ref ); return err; #elif __LP64__ /* No 64bit Carbon API on legacy platforms */ FT_UNUSED( ats_font_id ); FT_UNUSED( ats_font_ref ); return fnfErr; #else /* 32bit Carbon API on legacy platforms */ OSStatus err; FSSpec spec; err = ATSFontGetFileSpecification( ats_font_id, &spec ); if ( noErr == err ) err = FSpMakeFSRef( &spec, ats_font_ref ); return err; #endif }
DoS Overflow +Info
0
FT_ATSFontGetFileReference( ATSFontRef ats_font_id, FSRef* ats_font_ref ) { #if defined( MAC_OS_X_VERSION_10_5 ) && \ ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) OSStatus err; err = ATSFontGetFileReference( ats_font_id, ats_font_ref ); return err; #elif __LP64__ /* No 64bit Carbon API on legacy platforms */ FT_UNUSED( ats_font_id ); FT_UNUSED( ats_font_ref ); return fnfErr; #else /* 32bit Carbon API on legacy platforms */ OSStatus err; FSSpec spec; err = ATSFontGetFileSpecification( ats_font_id, &spec ); if ( noErr == err ) err = FSpMakeFSRef( &spec, ats_font_ref ); return err; #endif }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,511
FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, UInt8* path, UInt32 maxPathSize, FT_Long* face_index ) { FSRef ref; FT_Error err; err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); if ( err ) return err; if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) ) return FT_THROW( Unknown_File_Format ); return FT_Err_Ok; }
DoS Overflow +Info
0
FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, UInt8* path, UInt32 maxPathSize, FT_Long* face_index ) { FSRef ref; FT_Error err; err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); if ( err ) return err; if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) ) return FT_THROW( Unknown_File_Format ); return FT_Err_Ok; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,512
FT_GetFileRef_From_Mac_ATS_Name( const char* fontName, FSRef* ats_font_ref, FT_Long* face_index ) { CFStringRef cf_fontName; ATSFontRef ats_font_id; *face_index = 0; cf_fontName = CFStringCreateWithCString( NULL, fontName, kCFStringEncodingMacRoman ); ats_font_id = ATSFontFindFromName( cf_fontName, kATSOptionFlagsUnRestrictedScope ); CFRelease( cf_fontName ); if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) return FT_THROW( Unknown_File_Format ); if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) ) return FT_THROW( Unknown_File_Format ); /* face_index calculation by searching preceding fontIDs */ /* with same FSRef */ { ATSFontRef id2 = ats_font_id - 1; FSRef ref2; while ( id2 > 0 ) { if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) ) break; if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) ) break; id2 --; } *face_index = ats_font_id - ( id2 + 1 ); } return FT_Err_Ok; }
DoS Overflow +Info
0
FT_GetFileRef_From_Mac_ATS_Name( const char* fontName, FSRef* ats_font_ref, FT_Long* face_index ) { CFStringRef cf_fontName; ATSFontRef ats_font_id; *face_index = 0; cf_fontName = CFStringCreateWithCString( NULL, fontName, kCFStringEncodingMacRoman ); ats_font_id = ATSFontFindFromName( cf_fontName, kATSOptionFlagsUnRestrictedScope ); CFRelease( cf_fontName ); if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) return FT_THROW( Unknown_File_Format ); if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) ) return FT_THROW( Unknown_File_Format ); /* face_index calculation by searching preceding fontIDs */ /* with same FSRef */ { ATSFontRef id2 = ats_font_id - 1; FSRef ref2; while ( id2 > 0 ) { if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) ) break; if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) ) break; id2 --; } *face_index = ats_font_id - ( id2 + 1 ); } return FT_Err_Ok; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,513
FT_GetFile_From_Mac_ATS_Name( const char* fontName, FSSpec* pathSpec, FT_Long* face_index ) { #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) FT_UNUSED( fontName ); FT_UNUSED( pathSpec ); FT_UNUSED( face_index ); return FT_THROW( Unimplemented_Feature ); #else FSRef ref; FT_Error err; err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); if ( err ) return err; if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, pathSpec, NULL ) ) return FT_THROW( Unknown_File_Format ); return FT_Err_Ok; #endif }
DoS Overflow +Info
0
FT_GetFile_From_Mac_ATS_Name( const char* fontName, FSSpec* pathSpec, FT_Long* face_index ) { #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) FT_UNUSED( fontName ); FT_UNUSED( pathSpec ); FT_UNUSED( face_index ); return FT_THROW( Unimplemented_Feature ); #else FSRef ref; FT_Error err; err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); if ( err ) return err; if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, pathSpec, NULL ) ) return FT_THROW( Unknown_File_Format ); return FT_Err_Ok; #endif }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,514
FT_GetFile_From_Mac_Name( const char* fontName, FSSpec* pathSpec, FT_Long* face_index ) { FT_UNUSED( fontName ); FT_UNUSED( pathSpec ); FT_UNUSED( face_index ); return FT_THROW( Unimplemented_Feature ); }
DoS Overflow +Info
0
FT_GetFile_From_Mac_Name( const char* fontName, FSSpec* pathSpec, FT_Long* face_index ) { FT_UNUSED( fontName ); FT_UNUSED( pathSpec ); FT_UNUSED( face_index ); return FT_THROW( Unimplemented_Feature ); }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,515
FT_New_Face( FT_Library library, const char* pathname, FT_Long face_index, FT_Face* aface ) { FT_Open_Args args; FT_Error error; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) return FT_THROW( Invalid_Argument ); *aface = NULL; /* try resourcefork based font: LWFN, FFIL */ error = FT_New_Face_From_Resource( library, (UInt8 *)pathname, face_index, aface ); if ( error != 0 || *aface != NULL ) return error; /* let it fall through to normal loader (.ttf, .otf, etc.) */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); }
DoS Overflow +Info
0
FT_New_Face( FT_Library library, const char* pathname, FT_Long face_index, FT_Face* aface ) { FT_Open_Args args; FT_Error error; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) return FT_THROW( Invalid_Argument ); *aface = NULL; /* try resourcefork based font: LWFN, FFIL */ error = FT_New_Face_From_Resource( library, (UInt8 *)pathname, face_index, aface ); if ( error != 0 || *aface != NULL ) return error; /* let it fall through to normal loader (.ttf, .otf, etc.) */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,516
FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face* aface ) { short have_sfnt, have_lwfn = 0; ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; GetResInfo( fond, &fond_id, &fond_type, fond_name ); if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_THROW( Invalid_File_Format ); parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); if ( lwfn_file_name[0] ) { ResFileRefNum res; res = HomeResFile( fond ); if ( noErr != ResError() ) goto found_no_lwfn_file; { UInt8 path_fond[PATH_MAX]; FSRef ref; err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, NULL, NULL, NULL, &ref, NULL ); if ( noErr != err ) goto found_no_lwfn_file; err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( !error ) have_lwfn = 1; } } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) error = FT_New_Face_From_LWFN( library, path_lwfn, face_index, aface ); else error = FT_THROW( Unknown_File_Format ); found_no_lwfn_file: if ( have_sfnt && error ) error = FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return error; }
DoS Overflow +Info
0
FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face* aface ) { short have_sfnt, have_lwfn = 0; ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; GetResInfo( fond, &fond_id, &fond_type, fond_name ); if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_THROW( Invalid_File_Format ); parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); if ( lwfn_file_name[0] ) { ResFileRefNum res; res = HomeResFile( fond ); if ( noErr != ResError() ) goto found_no_lwfn_file; { UInt8 path_fond[PATH_MAX]; FSRef ref; err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, NULL, NULL, NULL, &ref, NULL ); if ( noErr != err ) goto found_no_lwfn_file; err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( !error ) have_lwfn = 1; } } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) error = FT_New_Face_From_LWFN( library, path_lwfn, face_index, aface ); else error = FT_THROW( Unknown_File_Format ); found_no_lwfn_file: if ( have_sfnt && error ) error = FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return error; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,517
FT_New_Face_From_FSRef( FT_Library library, const FSRef* ref, FT_Long face_index, FT_Face* aface ) { FT_Error error; FT_Open_Args args; OSErr err; UInt8 pathname[PATH_MAX]; if ( !ref ) return FT_THROW( Invalid_Argument ); err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); if ( err ) error = FT_THROW( Cannot_Open_Resource ); error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); if ( error != 0 || *aface != NULL ) return error; /* fallback to datafork font */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); }
DoS Overflow +Info
0
FT_New_Face_From_FSRef( FT_Library library, const FSRef* ref, FT_Long face_index, FT_Face* aface ) { FT_Error error; FT_Open_Args args; OSErr err; UInt8 pathname[PATH_MAX]; if ( !ref ) return FT_THROW( Invalid_Argument ); err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); if ( err ) error = FT_THROW( Cannot_Open_Resource ); error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); if ( error != 0 || *aface != NULL ) return error; /* fallback to datafork font */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,518
FT_New_Face_From_Resource( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { OSType file_type; FT_Error error; /* LWFN is a (very) specific file format, check for it explicitly */ file_type = get_file_type_from_path( pathname ); if ( file_type == TTAG_LWFN ) return FT_New_Face_From_LWFN( library, pathname, face_index, aface ); /* Otherwise the file type doesn't matter (there are more than */ /* `FFIL' and `tfil'). Just try opening it as a font suitcase; */ /* if it works, fine. */ error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface ); if ( error == 0 ) return error; /* let it fall through to normal loader (.ttf, .otf, etc.); */ /* we signal this by returning no error and no FT_Face */ *aface = NULL; return 0; }
DoS Overflow +Info
0
FT_New_Face_From_Resource( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { OSType file_type; FT_Error error; /* LWFN is a (very) specific file format, check for it explicitly */ file_type = get_file_type_from_path( pathname ); if ( file_type == TTAG_LWFN ) return FT_New_Face_From_LWFN( library, pathname, face_index, aface ); /* Otherwise the file type doesn't matter (there are more than */ /* `FFIL' and `tfil'). Just try opening it as a font suitcase; */ /* if it works, fine. */ error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface ); if ( error == 0 ) return error; /* let it fall through to normal loader (.ttf, .otf, etc.); */ /* we signal this by returning no error and no FT_Face */ *aface = NULL; return 0; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,519
FT_New_Face_From_SFNT( FT_Library library, ResID sfnt_id, FT_Long face_index, FT_Face* aface ) { Handle sfnt = NULL; FT_Byte* sfnt_data; size_t sfnt_size; FT_Error error = FT_Err_Ok; FT_Memory memory = library->memory; int is_cff, is_sfnt_ps; sfnt = GetResource( TTAG_sfnt, sfnt_id ); if ( sfnt == NULL ) return FT_THROW( Invalid_Handle ); sfnt_size = (FT_ULong)GetHandleSize( sfnt ); if ( FT_ALLOC( sfnt_data, (FT_Long)sfnt_size ) ) { ReleaseResource( sfnt ); return error; } ft_memcpy( sfnt_data, *sfnt, sfnt_size ); ReleaseResource( sfnt ); is_cff = sfnt_size > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 ); is_sfnt_ps = sfnt_size > 4 && !ft_memcmp( sfnt_data, "typ1", 4 ); if ( is_sfnt_ps ) { FT_Stream stream; if ( FT_NEW( stream ) ) goto Try_OpenType; FT_Stream_OpenMemory( stream, sfnt_data, sfnt_size ); if ( !open_face_PS_from_sfnt_stream( library, stream, face_index, 0, NULL, aface ) ) { FT_Stream_Close( stream ); FT_FREE( stream ); FT_FREE( sfnt_data ); goto Exit; } FT_FREE( stream ); } Try_OpenType: error = open_face_from_buffer( library, sfnt_data, sfnt_size, face_index, is_cff ? "cff" : "truetype", aface ); Exit: return error; }
DoS Overflow +Info
0
FT_New_Face_From_SFNT( FT_Library library, ResID sfnt_id, FT_Long face_index, FT_Face* aface ) { Handle sfnt = NULL; FT_Byte* sfnt_data; size_t sfnt_size; FT_Error error = FT_Err_Ok; FT_Memory memory = library->memory; int is_cff, is_sfnt_ps; sfnt = GetResource( TTAG_sfnt, sfnt_id ); if ( sfnt == NULL ) return FT_THROW( Invalid_Handle ); sfnt_size = (FT_ULong)GetHandleSize( sfnt ); if ( FT_ALLOC( sfnt_data, (FT_Long)sfnt_size ) ) { ReleaseResource( sfnt ); return error; } ft_memcpy( sfnt_data, *sfnt, sfnt_size ); ReleaseResource( sfnt ); is_cff = sfnt_size > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 ); is_sfnt_ps = sfnt_size > 4 && !ft_memcmp( sfnt_data, "typ1", 4 ); if ( is_sfnt_ps ) { FT_Stream stream; if ( FT_NEW( stream ) ) goto Try_OpenType; FT_Stream_OpenMemory( stream, sfnt_data, sfnt_size ); if ( !open_face_PS_from_sfnt_stream( library, stream, face_index, 0, NULL, aface ) ) { FT_Stream_Close( stream ); FT_FREE( stream ); FT_FREE( sfnt_data ); goto Exit; } FT_FREE( stream ); } Try_OpenType: error = open_face_from_buffer( library, sfnt_data, sfnt_size, face_index, is_cff ? "cff" : "truetype", aface ); Exit: return error; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,520
FT_New_Face_From_Suitcase( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { FT_Error error = FT_ERR( Cannot_Open_Resource ); ResFileRefNum res_ref; ResourceIndex res_index; Handle fond; short num_faces_in_res; if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) ) return FT_THROW( Cannot_Open_Resource ); UseResFile( res_ref ); if ( ResError() ) return FT_THROW( Cannot_Open_Resource ); num_faces_in_res = 0; for ( res_index = 1; ; ++res_index ) { short num_faces_in_fond; fond = Get1IndResource( TTAG_FOND, res_index ); if ( ResError() ) break; num_faces_in_fond = count_faces( fond, pathname ); num_faces_in_res += num_faces_in_fond; if ( 0 <= face_index && face_index < num_faces_in_fond && error ) error = FT_New_Face_From_FOND( library, fond, face_index, aface ); face_index -= num_faces_in_fond; } CloseResFile( res_ref ); if ( !error && aface && *aface ) (*aface)->num_faces = num_faces_in_res; return error; }
DoS Overflow +Info
0
FT_New_Face_From_Suitcase( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { FT_Error error = FT_ERR( Cannot_Open_Resource ); ResFileRefNum res_ref; ResourceIndex res_index; Handle fond; short num_faces_in_res; if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) ) return FT_THROW( Cannot_Open_Resource ); UseResFile( res_ref ); if ( ResError() ) return FT_THROW( Cannot_Open_Resource ); num_faces_in_res = 0; for ( res_index = 1; ; ++res_index ) { short num_faces_in_fond; fond = Get1IndResource( TTAG_FOND, res_index ); if ( ResError() ) break; num_faces_in_fond = count_faces( fond, pathname ); num_faces_in_res += num_faces_in_fond; if ( 0 <= face_index && face_index < num_faces_in_fond && error ) error = FT_New_Face_From_FOND( library, fond, face_index, aface ); face_index -= num_faces_in_fond; } CloseResFile( res_ref ); if ( !error && aface && *aface ) (*aface)->num_faces = num_faces_in_res; return error; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,521
count_faces_scalable( char* fond_data ) { AsscEntry* assoc; short i, face, face_all; face_all = EndianS16_BtoN( *( (short *)( fond_data + sizeof ( FamRec ) ) ) ) + 1; assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 ); face = 0; for ( i = 0; i < face_all; i++ ) { if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) ) face++; } return face; }
DoS Overflow +Info
0
count_faces_scalable( char* fond_data ) { AsscEntry* assoc; short i, face, face_all; face_all = EndianS16_BtoN( *( (short *)( fond_data + sizeof ( FamRec ) ) ) ) + 1; assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 ); face = 0; for ( i = 0; i < face_all; i++ ) { if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) ) face++; } return face; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,522
create_lwfn_name( char* ps_name, Str255 lwfn_file_name ) { int max = 5, count = 0; FT_Byte* p = lwfn_file_name; FT_Byte* q = (FT_Byte*)ps_name; lwfn_file_name[0] = 0; while ( *q ) { if ( ft_isupper( *q ) ) { if ( count ) max = 3; count = 0; } if ( count < max && ( ft_isalnum( *q ) || *q == '_' ) ) { *++p = *q; lwfn_file_name[0]++; count++; } q++; } }
DoS Overflow +Info
0
create_lwfn_name( char* ps_name, Str255 lwfn_file_name ) { int max = 5, count = 0; FT_Byte* p = lwfn_file_name; FT_Byte* q = (FT_Byte*)ps_name; lwfn_file_name[0] = 0; while ( *q ) { if ( ft_isupper( *q ) ) { if ( count ) max = 3; count = 0; } if ( count < max && ( ft_isalnum( *q ) || *q == '_' ) ) { *++p = *q; lwfn_file_name[0]++; count++; } q++; } }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,523
get_file_type_from_path( const UInt8* pathname ) { FSRef ref; FSCatalogInfo info; if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) ) return ( OSType ) 0; if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info, NULL, NULL, NULL ) ) return ( OSType ) 0; return ((FInfo *)(info.finderInfo))->fdType; }
DoS Overflow +Info
0
get_file_type_from_path( const UInt8* pathname ) { FSRef ref; FSCatalogInfo info; if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) ) return ( OSType ) 0; if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info, NULL, NULL, NULL ) ) return ( OSType ) 0; return ((FInfo *)(info.finderInfo))->fdType; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,524
lookup_lwfn_by_fond( const UInt8* path_fond, ConstStr255Param base_lwfn, UInt8* path_lwfn, size_t path_size ) { FSRef ref, par_ref; size_t dirname_len; /* Pathname for FSRef can be in various formats: HFS, HFS+, and POSIX. */ /* We should not extract parent directory by string manipulation. */ if ( noErr != FSPathMakeRef( path_fond, &ref, FALSE ) ) return FT_THROW( Invalid_Argument ); if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, NULL, &par_ref ) ) return FT_THROW( Invalid_Argument ); if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) ) return FT_THROW( Invalid_Argument ); if ( ft_strlen( (char *)path_lwfn ) + 1 + base_lwfn[0] > path_size ) return FT_THROW( Invalid_Argument ); /* now we have absolute dirname in path_lwfn */ ft_strcat( (char *)path_lwfn, "/" ); dirname_len = ft_strlen( (char *)path_lwfn ); ft_strcat( (char *)path_lwfn, (char *)base_lwfn + 1 ); path_lwfn[dirname_len + base_lwfn[0]] = '\0'; if ( noErr != FSPathMakeRef( path_lwfn, &ref, FALSE ) ) return FT_THROW( Cannot_Open_Resource ); if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, NULL, NULL ) ) return FT_THROW( Cannot_Open_Resource ); return FT_Err_Ok; }
DoS Overflow +Info
0
lookup_lwfn_by_fond( const UInt8* path_fond, ConstStr255Param base_lwfn, UInt8* path_lwfn, size_t path_size ) { FSRef ref, par_ref; size_t dirname_len; /* Pathname for FSRef can be in various formats: HFS, HFS+, and POSIX. */ /* We should not extract parent directory by string manipulation. */ if ( noErr != FSPathMakeRef( path_fond, &ref, FALSE ) ) return FT_THROW( Invalid_Argument ); if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, NULL, &par_ref ) ) return FT_THROW( Invalid_Argument ); if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) ) return FT_THROW( Invalid_Argument ); if ( ft_strlen( (char *)path_lwfn ) + 1 + base_lwfn[0] > path_size ) return FT_THROW( Invalid_Argument ); /* now we have absolute dirname in path_lwfn */ ft_strcat( (char *)path_lwfn, "/" ); dirname_len = ft_strlen( (char *)path_lwfn ); ft_strcat( (char *)path_lwfn, (char *)base_lwfn + 1 ); path_lwfn[dirname_len + base_lwfn[0]] = '\0'; if ( noErr != FSPathMakeRef( path_lwfn, &ref, FALSE ) ) return FT_THROW( Cannot_Open_Resource ); if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, NULL, NULL ) ) return FT_THROW( Cannot_Open_Resource ); return FT_Err_Ok; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,525
read_lwfn( FT_Memory memory, ResFileRefNum res, FT_Byte** pfb_data, FT_ULong* size ) { FT_Error error = FT_Err_Ok; ResID res_id; unsigned char *buffer, *p, *size_p = NULL; FT_ULong total_size = 0; FT_ULong old_total_size = 0; FT_ULong post_size, pfb_chunk_size; Handle post_data; char code, last_code; UseResFile( res ); /* First pass: load all POST resources, and determine the size of */ /* the output buffer. */ res_id = 501; last_code = -1; for (;;) { post_data = Get1Resource( TTAG_POST, res_id++ ); if ( post_data == NULL ) break; /* we are done */ code = (*post_data)[0]; if ( code != last_code ) { if ( code == 5 ) total_size += 2; /* just the end code */ else total_size += 6; /* code + 4 bytes chunk length */ } total_size += GetHandleSize( post_data ) - 2; last_code = code; /* detect integer overflows */ if ( total_size < old_total_size ) { error = FT_THROW( Array_Too_Large ); goto Error; } old_total_size = total_size; } if ( FT_ALLOC( buffer, (FT_Long)total_size ) ) goto Error; /* Second pass: append all POST data to the buffer, add PFB fields. */ /* Glue all consecutive chunks of the same type together. */ p = buffer; res_id = 501; last_code = -1; pfb_chunk_size = 0; for (;;) { post_data = Get1Resource( TTAG_POST, res_id++ ); if ( post_data == NULL ) break; /* we are done */ post_size = (FT_ULong)GetHandleSize( post_data ) - 2; code = (*post_data)[0]; if ( code != last_code ) { if ( last_code != -1 ) { /* we are done adding a chunk, fill in the size field */ if ( size_p != NULL ) { *size_p++ = (FT_Byte)( pfb_chunk_size & 0xFF ); *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF ); *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF ); *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF ); } pfb_chunk_size = 0; } *p++ = 0x80; if ( code == 5 ) *p++ = 0x03; /* the end */ else if ( code == 2 ) *p++ = 0x02; /* binary segment */ else *p++ = 0x01; /* ASCII segment */ if ( code != 5 ) { size_p = p; /* save for later */ p += 4; /* make space for size field */ } } ft_memcpy( p, *post_data + 2, post_size ); pfb_chunk_size += post_size; p += post_size; last_code = code; } *pfb_data = buffer; *size = total_size; Error: CloseResFile( res ); return error; }
DoS Overflow +Info
0
read_lwfn( FT_Memory memory, ResFileRefNum res, FT_Byte** pfb_data, FT_ULong* size ) { FT_Error error = FT_Err_Ok; ResID res_id; unsigned char *buffer, *p, *size_p = NULL; FT_ULong total_size = 0; FT_ULong old_total_size = 0; FT_ULong post_size, pfb_chunk_size; Handle post_data; char code, last_code; UseResFile( res ); /* First pass: load all POST resources, and determine the size of */ /* the output buffer. */ res_id = 501; last_code = -1; for (;;) { post_data = Get1Resource( TTAG_POST, res_id++ ); if ( post_data == NULL ) break; /* we are done */ code = (*post_data)[0]; if ( code != last_code ) { if ( code == 5 ) total_size += 2; /* just the end code */ else total_size += 6; /* code + 4 bytes chunk length */ } total_size += GetHandleSize( post_data ) - 2; last_code = code; /* detect integer overflows */ if ( total_size < old_total_size ) { error = FT_THROW( Array_Too_Large ); goto Error; } old_total_size = total_size; } if ( FT_ALLOC( buffer, (FT_Long)total_size ) ) goto Error; /* Second pass: append all POST data to the buffer, add PFB fields. */ /* Glue all consecutive chunks of the same type together. */ p = buffer; res_id = 501; last_code = -1; pfb_chunk_size = 0; for (;;) { post_data = Get1Resource( TTAG_POST, res_id++ ); if ( post_data == NULL ) break; /* we are done */ post_size = (FT_ULong)GetHandleSize( post_data ) - 2; code = (*post_data)[0]; if ( code != last_code ) { if ( last_code != -1 ) { /* we are done adding a chunk, fill in the size field */ if ( size_p != NULL ) { *size_p++ = (FT_Byte)( pfb_chunk_size & 0xFF ); *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF ); *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF ); *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF ); } pfb_chunk_size = 0; } *p++ = 0x80; if ( code == 5 ) *p++ = 0x03; /* the end */ else if ( code == 2 ) *p++ = 0x02; /* binary segment */ else *p++ = 0x01; /* ASCII segment */ if ( code != 5 ) { size_p = p; /* save for later */ p += 4; /* make space for size field */ } } ft_memcpy( p, *post_data + 2, post_size ); pfb_chunk_size += post_size; p += post_size; last_code = code; } *pfb_data = buffer; *size = total_size; Error: CloseResFile( res ); return error; }
@@ -440,9 +440,10 @@ style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); + string_count = FT_MIN( 64, string_count ); p += sizeof ( short ); - for ( i = 0; i < string_count && i < 64; i++ ) + for ( i = 0; i < string_count; i++ ) { names[i] = p; p += names[i][0]; @@ -459,7 +460,7 @@ ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) + style->indexes[face_index] <= string_count ) { unsigned char* suffixes = names[style->indexes[face_index] - 1];
CWE-119
null
null
5,526
pcf_get_accel( FT_Stream stream, PCF_Face face, FT_ULong type ) { FT_ULong format, size; FT_Error error; PCF_Accel accel = &face->accel; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, type, &format, &size ); if ( error ) goto Bail; if ( FT_READ_ULONG_LE( format ) ) goto Bail; if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) && !PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) goto Bail; if ( PCF_BYTE_ORDER( format ) == MSBFirst ) { if ( FT_STREAM_READ_FIELDS( pcf_accel_msb_header, accel ) ) goto Bail; } else { if ( FT_STREAM_READ_FIELDS( pcf_accel_header, accel ) ) goto Bail; } error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->minbounds) ); if ( error ) goto Bail; error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->maxbounds) ); if ( error ) goto Bail; if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) { error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->ink_minbounds) ); if ( error ) goto Bail; error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->ink_maxbounds) ); if ( error ) goto Bail; } else { accel->ink_minbounds = accel->minbounds; /* I'm not sure about this */ accel->ink_maxbounds = accel->maxbounds; } Bail: return error; }
DoS Overflow
0
pcf_get_accel( FT_Stream stream, PCF_Face face, FT_ULong type ) { FT_ULong format, size; FT_Error error; PCF_Accel accel = &face->accel; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, type, &format, &size ); if ( error ) goto Bail; if ( FT_READ_ULONG_LE( format ) ) goto Bail; if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) && !PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) goto Bail; if ( PCF_BYTE_ORDER( format ) == MSBFirst ) { if ( FT_STREAM_READ_FIELDS( pcf_accel_msb_header, accel ) ) goto Bail; } else { if ( FT_STREAM_READ_FIELDS( pcf_accel_header, accel ) ) goto Bail; } error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->minbounds) ); if ( error ) goto Bail; error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->maxbounds) ); if ( error ) goto Bail; if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) { error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->ink_minbounds) ); if ( error ) goto Bail; error = pcf_get_metric( stream, format & ( ~PCF_FORMAT_MASK ), &(accel->ink_maxbounds) ); if ( error ) goto Bail; } else { accel->ink_minbounds = accel->minbounds; /* I'm not sure about this */ accel->ink_maxbounds = accel->maxbounds; } Bail: return error; }
@@ -830,6 +830,15 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
CWE-189
null
null
5,527
pcf_get_bitmaps( FT_Stream stream, PCF_Face face ) { FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_Long* offsets = NULL; FT_Long bitmapSizes[GLYPHPADOPTIONS]; FT_ULong format, size; FT_ULong nbitmaps, i, sizebitmaps = 0; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, PCF_BITMAPS, &format, &size ); if ( error ) return error; error = FT_Stream_EnterFrame( stream, 8 ); if ( error ) return error; format = FT_GET_ULONG_LE(); if ( PCF_BYTE_ORDER( format ) == MSBFirst ) nbitmaps = FT_GET_ULONG(); else nbitmaps = FT_GET_ULONG_LE(); FT_Stream_ExitFrame( stream ); if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); FT_TRACE4(( "pcf_get_bitmaps:\n" )); FT_TRACE4(( " number of bitmaps: %d\n", nbitmaps )); /* XXX: PCF_Face->nmetrics is singed FT_Long, see pcf.h */ if ( face->nmetrics < 0 || nbitmaps != ( FT_ULong )face->nmetrics ) return FT_THROW( Invalid_File_Format ); if ( FT_NEW_ARRAY( offsets, nbitmaps ) ) return error; for ( i = 0; i < nbitmaps; i++ ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_LONG( offsets[i] ); else (void)FT_READ_LONG_LE( offsets[i] ); FT_TRACE5(( " bitmap %d: offset %ld (0x%lX)\n", i, offsets[i], offsets[i] )); } if ( error ) goto Bail; for ( i = 0; i < GLYPHPADOPTIONS; i++ ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_LONG( bitmapSizes[i] ); else (void)FT_READ_LONG_LE( bitmapSizes[i] ); if ( error ) goto Bail; sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX( format )]; FT_TRACE4(( " padding %d implies a size of %ld\n", i, bitmapSizes[i] )); } FT_TRACE4(( " %d bitmaps, padding index %ld\n", nbitmaps, PCF_GLYPH_PAD_INDEX( format ) )); FT_TRACE4(( " bitmap size = %d\n", sizebitmaps )); FT_UNUSED( sizebitmaps ); /* only used for debugging */ for ( i = 0; i < nbitmaps; i++ ) { /* rough estimate */ if ( ( offsets[i] < 0 ) || ( (FT_ULong)offsets[i] > size ) ) { FT_TRACE0(( "pcf_get_bitmaps:" " invalid offset to bitmap data of glyph %d\n", i )); } else face->metrics[i].bits = stream->pos + offsets[i]; } face->bitmapsFormat = format; Bail: FT_FREE( offsets ); return error; }
DoS Overflow
0
pcf_get_bitmaps( FT_Stream stream, PCF_Face face ) { FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_Long* offsets = NULL; FT_Long bitmapSizes[GLYPHPADOPTIONS]; FT_ULong format, size; FT_ULong nbitmaps, i, sizebitmaps = 0; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, PCF_BITMAPS, &format, &size ); if ( error ) return error; error = FT_Stream_EnterFrame( stream, 8 ); if ( error ) return error; format = FT_GET_ULONG_LE(); if ( PCF_BYTE_ORDER( format ) == MSBFirst ) nbitmaps = FT_GET_ULONG(); else nbitmaps = FT_GET_ULONG_LE(); FT_Stream_ExitFrame( stream ); if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); FT_TRACE4(( "pcf_get_bitmaps:\n" )); FT_TRACE4(( " number of bitmaps: %d\n", nbitmaps )); /* XXX: PCF_Face->nmetrics is singed FT_Long, see pcf.h */ if ( face->nmetrics < 0 || nbitmaps != ( FT_ULong )face->nmetrics ) return FT_THROW( Invalid_File_Format ); if ( FT_NEW_ARRAY( offsets, nbitmaps ) ) return error; for ( i = 0; i < nbitmaps; i++ ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_LONG( offsets[i] ); else (void)FT_READ_LONG_LE( offsets[i] ); FT_TRACE5(( " bitmap %d: offset %ld (0x%lX)\n", i, offsets[i], offsets[i] )); } if ( error ) goto Bail; for ( i = 0; i < GLYPHPADOPTIONS; i++ ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_LONG( bitmapSizes[i] ); else (void)FT_READ_LONG_LE( bitmapSizes[i] ); if ( error ) goto Bail; sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX( format )]; FT_TRACE4(( " padding %d implies a size of %ld\n", i, bitmapSizes[i] )); } FT_TRACE4(( " %d bitmaps, padding index %ld\n", nbitmaps, PCF_GLYPH_PAD_INDEX( format ) )); FT_TRACE4(( " bitmap size = %d\n", sizebitmaps )); FT_UNUSED( sizebitmaps ); /* only used for debugging */ for ( i = 0; i < nbitmaps; i++ ) { /* rough estimate */ if ( ( offsets[i] < 0 ) || ( (FT_ULong)offsets[i] > size ) ) { FT_TRACE0(( "pcf_get_bitmaps:" " invalid offset to bitmap data of glyph %d\n", i )); } else face->metrics[i].bits = stream->pos + offsets[i]; } face->bitmapsFormat = format; Bail: FT_FREE( offsets ); return error; }
@@ -830,6 +830,15 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
CWE-189
null
null
5,528
pcf_get_metric( FT_Stream stream, FT_ULong format, PCF_Metric metric ) { FT_Error error = FT_Err_Ok; if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { const FT_Frame_Field* fields; /* parsing normal metrics */ fields = PCF_BYTE_ORDER( format ) == MSBFirst ? pcf_metric_msb_header : pcf_metric_header; /* the following sets `error' but doesn't return in case of failure */ (void)FT_STREAM_READ_FIELDS( fields, metric ); } else { PCF_Compressed_MetricRec compr; /* parsing compressed metrics */ if ( FT_STREAM_READ_FIELDS( pcf_compressed_metric_header, &compr ) ) goto Exit; metric->leftSideBearing = (FT_Short)( compr.leftSideBearing - 0x80 ); metric->rightSideBearing = (FT_Short)( compr.rightSideBearing - 0x80 ); metric->characterWidth = (FT_Short)( compr.characterWidth - 0x80 ); metric->ascent = (FT_Short)( compr.ascent - 0x80 ); metric->descent = (FT_Short)( compr.descent - 0x80 ); metric->attributes = 0; } Exit: return error; }
DoS Overflow
0
pcf_get_metric( FT_Stream stream, FT_ULong format, PCF_Metric metric ) { FT_Error error = FT_Err_Ok; if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { const FT_Frame_Field* fields; /* parsing normal metrics */ fields = PCF_BYTE_ORDER( format ) == MSBFirst ? pcf_metric_msb_header : pcf_metric_header; /* the following sets `error' but doesn't return in case of failure */ (void)FT_STREAM_READ_FIELDS( fields, metric ); } else { PCF_Compressed_MetricRec compr; /* parsing compressed metrics */ if ( FT_STREAM_READ_FIELDS( pcf_compressed_metric_header, &compr ) ) goto Exit; metric->leftSideBearing = (FT_Short)( compr.leftSideBearing - 0x80 ); metric->rightSideBearing = (FT_Short)( compr.rightSideBearing - 0x80 ); metric->characterWidth = (FT_Short)( compr.characterWidth - 0x80 ); metric->ascent = (FT_Short)( compr.ascent - 0x80 ); metric->descent = (FT_Short)( compr.descent - 0x80 ); metric->attributes = 0; } Exit: return error; }
@@ -830,6 +830,15 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
CWE-189
null
null
5,529
pcf_get_metrics( FT_Stream stream, PCF_Face face ) { FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_ULong format, size; PCF_Metric metrics = 0; FT_ULong nmetrics, i; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, PCF_METRICS, &format, &size ); if ( error ) return error; if ( FT_READ_ULONG_LE( format ) ) goto Bail; if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) && !PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ) return FT_THROW( Invalid_File_Format ); if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_ULONG( nmetrics ); else (void)FT_READ_ULONG_LE( nmetrics ); } else { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_USHORT( nmetrics ); else (void)FT_READ_USHORT_LE( nmetrics ); } if ( error ) return FT_THROW( Invalid_File_Format ); face->nmetrics = nmetrics; if ( !nmetrics ) return FT_THROW( Invalid_Table ); FT_TRACE4(( "pcf_get_metrics:\n" )); FT_TRACE4(( " number of metrics: %d\n", nmetrics )); /* rough estimate */ if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { if ( nmetrics > size / PCF_METRIC_SIZE ) return FT_THROW( Invalid_Table ); } else { if ( nmetrics > size / PCF_COMPRESSED_METRIC_SIZE ) return FT_THROW( Invalid_Table ); } if ( FT_NEW_ARRAY( face->metrics, nmetrics ) ) return FT_THROW( Out_Of_Memory ); metrics = face->metrics; for ( i = 0; i < nmetrics; i++ ) { error = pcf_get_metric( stream, format, metrics + i ); metrics[i].bits = 0; FT_TRACE5(( " idx %d: width=%d, " "lsb=%d, rsb=%d, ascent=%d, descent=%d, swidth=%d\n", i, ( metrics + i )->characterWidth, ( metrics + i )->leftSideBearing, ( metrics + i )->rightSideBearing, ( metrics + i )->ascent, ( metrics + i )->descent, ( metrics + i )->attributes )); if ( error ) break; } if ( error ) FT_FREE( face->metrics ); Bail: return error; }
DoS Overflow
0
pcf_get_metrics( FT_Stream stream, PCF_Face face ) { FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_ULong format, size; PCF_Metric metrics = 0; FT_ULong nmetrics, i; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, PCF_METRICS, &format, &size ); if ( error ) return error; if ( FT_READ_ULONG_LE( format ) ) goto Bail; if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) && !PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ) return FT_THROW( Invalid_File_Format ); if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_ULONG( nmetrics ); else (void)FT_READ_ULONG_LE( nmetrics ); } else { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_USHORT( nmetrics ); else (void)FT_READ_USHORT_LE( nmetrics ); } if ( error ) return FT_THROW( Invalid_File_Format ); face->nmetrics = nmetrics; if ( !nmetrics ) return FT_THROW( Invalid_Table ); FT_TRACE4(( "pcf_get_metrics:\n" )); FT_TRACE4(( " number of metrics: %d\n", nmetrics )); /* rough estimate */ if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { if ( nmetrics > size / PCF_METRIC_SIZE ) return FT_THROW( Invalid_Table ); } else { if ( nmetrics > size / PCF_COMPRESSED_METRIC_SIZE ) return FT_THROW( Invalid_Table ); } if ( FT_NEW_ARRAY( face->metrics, nmetrics ) ) return FT_THROW( Out_Of_Memory ); metrics = face->metrics; for ( i = 0; i < nmetrics; i++ ) { error = pcf_get_metric( stream, format, metrics + i ); metrics[i].bits = 0; FT_TRACE5(( " idx %d: width=%d, " "lsb=%d, rsb=%d, ascent=%d, descent=%d, swidth=%d\n", i, ( metrics + i )->characterWidth, ( metrics + i )->leftSideBearing, ( metrics + i )->rightSideBearing, ( metrics + i )->ascent, ( metrics + i )->descent, ( metrics + i )->attributes )); if ( error ) break; } if ( error ) FT_FREE( face->metrics ); Bail: return error; }
@@ -830,6 +830,15 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
CWE-189
null
null
5,530
pcf_get_properties( FT_Stream stream, PCF_Face face ) { PCF_ParseProperty props = 0; PCF_Property properties = NULL; FT_ULong nprops, i; FT_ULong format, size; FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_ULong string_size; FT_String* strings = 0; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, PCF_PROPERTIES, &format, &size ); if ( error ) goto Bail; if ( FT_READ_ULONG_LE( format ) ) goto Bail; FT_TRACE4(( "pcf_get_properties:\n" )); FT_TRACE4(( " format = %ld\n", format )); if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) goto Bail; if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_ULONG( nprops ); else (void)FT_READ_ULONG_LE( nprops ); if ( error ) goto Bail; FT_TRACE4(( " nprop = %d (truncate %d props)\n", (int)nprops, nprops - (int)nprops )); nprops = (int)nprops; /* rough estimate */ if ( nprops > size / PCF_PROPERTY_SIZE ) { error = FT_THROW( Invalid_Table ); goto Bail; } face->nprops = (int)nprops; if ( FT_NEW_ARRAY( props, nprops ) ) goto Bail; for ( i = 0; i < nprops; i++ ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) { if ( FT_STREAM_READ_FIELDS( pcf_property_msb_header, props + i ) ) goto Bail; } else { if ( FT_STREAM_READ_FIELDS( pcf_property_header, props + i ) ) goto Bail; } } /* pad the property array */ /* */ /* clever here - nprops is the same as the number of odd-units read, */ /* as only isStringProp are odd length (Keith Packard) */ /* */ if ( nprops & 3 ) { i = 4 - ( nprops & 3 ); if ( FT_STREAM_SKIP( i ) ) { error = FT_THROW( Invalid_Stream_Skip ); goto Bail; } } if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_ULONG( string_size ); else (void)FT_READ_ULONG_LE( string_size ); if ( error ) goto Bail; FT_TRACE4(( " string_size = %ld\n", string_size )); /* rough estimate */ if ( string_size > size - nprops * PCF_PROPERTY_SIZE ) { error = FT_THROW( Invalid_Table ); goto Bail; } /* allocate one more byte so that we have a final null byte */ if ( FT_NEW_ARRAY( strings, string_size + 1 ) ) goto Bail; error = FT_Stream_Read( stream, (FT_Byte*)strings, string_size ); if ( error ) goto Bail; if ( FT_NEW_ARRAY( properties, nprops ) ) goto Bail; face->properties = properties; for ( i = 0; i < nprops; i++ ) { FT_Long name_offset = props[i].name; if ( ( name_offset < 0 ) || ( (FT_ULong)name_offset > string_size ) ) { error = FT_THROW( Invalid_Offset ); goto Bail; } if ( FT_STRDUP( properties[i].name, strings + name_offset ) ) goto Bail; FT_TRACE4(( " %s:", properties[i].name )); properties[i].isString = props[i].isString; if ( props[i].isString ) { FT_Long value_offset = props[i].value; if ( ( value_offset < 0 ) || ( (FT_ULong)value_offset > string_size ) ) { error = FT_THROW( Invalid_Offset ); goto Bail; } if ( FT_STRDUP( properties[i].value.atom, strings + value_offset ) ) goto Bail; FT_TRACE4(( " `%s'\n", properties[i].value.atom )); } else { properties[i].value.l = props[i].value; FT_TRACE4(( " %d\n", properties[i].value.l )); } } error = FT_Err_Ok; Bail: FT_FREE( props ); FT_FREE( strings ); return error; }
DoS Overflow
0
pcf_get_properties( FT_Stream stream, PCF_Face face ) { PCF_ParseProperty props = 0; PCF_Property properties = NULL; FT_ULong nprops, i; FT_ULong format, size; FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_ULong string_size; FT_String* strings = 0; error = pcf_seek_to_table_type( stream, face->toc.tables, face->toc.count, PCF_PROPERTIES, &format, &size ); if ( error ) goto Bail; if ( FT_READ_ULONG_LE( format ) ) goto Bail; FT_TRACE4(( "pcf_get_properties:\n" )); FT_TRACE4(( " format = %ld\n", format )); if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) goto Bail; if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_ULONG( nprops ); else (void)FT_READ_ULONG_LE( nprops ); if ( error ) goto Bail; FT_TRACE4(( " nprop = %d (truncate %d props)\n", (int)nprops, nprops - (int)nprops )); nprops = (int)nprops; /* rough estimate */ if ( nprops > size / PCF_PROPERTY_SIZE ) { error = FT_THROW( Invalid_Table ); goto Bail; } face->nprops = (int)nprops; if ( FT_NEW_ARRAY( props, nprops ) ) goto Bail; for ( i = 0; i < nprops; i++ ) { if ( PCF_BYTE_ORDER( format ) == MSBFirst ) { if ( FT_STREAM_READ_FIELDS( pcf_property_msb_header, props + i ) ) goto Bail; } else { if ( FT_STREAM_READ_FIELDS( pcf_property_header, props + i ) ) goto Bail; } } /* pad the property array */ /* */ /* clever here - nprops is the same as the number of odd-units read, */ /* as only isStringProp are odd length (Keith Packard) */ /* */ if ( nprops & 3 ) { i = 4 - ( nprops & 3 ); if ( FT_STREAM_SKIP( i ) ) { error = FT_THROW( Invalid_Stream_Skip ); goto Bail; } } if ( PCF_BYTE_ORDER( format ) == MSBFirst ) (void)FT_READ_ULONG( string_size ); else (void)FT_READ_ULONG_LE( string_size ); if ( error ) goto Bail; FT_TRACE4(( " string_size = %ld\n", string_size )); /* rough estimate */ if ( string_size > size - nprops * PCF_PROPERTY_SIZE ) { error = FT_THROW( Invalid_Table ); goto Bail; } /* allocate one more byte so that we have a final null byte */ if ( FT_NEW_ARRAY( strings, string_size + 1 ) ) goto Bail; error = FT_Stream_Read( stream, (FT_Byte*)strings, string_size ); if ( error ) goto Bail; if ( FT_NEW_ARRAY( properties, nprops ) ) goto Bail; face->properties = properties; for ( i = 0; i < nprops; i++ ) { FT_Long name_offset = props[i].name; if ( ( name_offset < 0 ) || ( (FT_ULong)name_offset > string_size ) ) { error = FT_THROW( Invalid_Offset ); goto Bail; } if ( FT_STRDUP( properties[i].name, strings + name_offset ) ) goto Bail; FT_TRACE4(( " %s:", properties[i].name )); properties[i].isString = props[i].isString; if ( props[i].isString ) { FT_Long value_offset = props[i].value; if ( ( value_offset < 0 ) || ( (FT_ULong)value_offset > string_size ) ) { error = FT_THROW( Invalid_Offset ); goto Bail; } if ( FT_STRDUP( properties[i].value.atom, strings + value_offset ) ) goto Bail; FT_TRACE4(( " `%s'\n", properties[i].value.atom )); } else { properties[i].value.l = props[i].value; FT_TRACE4(( " %d\n", properties[i].value.l )); } } error = FT_Err_Ok; Bail: FT_FREE( props ); FT_FREE( strings ); return error; }
@@ -830,6 +830,15 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
CWE-189
null
null
5,531
pcf_has_table_type( PCF_Table tables, FT_ULong ntables, /* same as PCF_Toc->count */ FT_ULong type ) { FT_ULong i; for ( i = 0; i < ntables; i++ ) if ( tables[i].type == type ) return TRUE; return FALSE; }
DoS Overflow
0
pcf_has_table_type( PCF_Table tables, FT_ULong ntables, /* same as PCF_Toc->count */ FT_ULong type ) { FT_ULong i; for ( i = 0; i < ntables; i++ ) if ( tables[i].type == type ) return TRUE; return FALSE; }
@@ -830,6 +830,15 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
CWE-189
null
null
5,532
pcf_interpret_style( PCF_Face pcf ) { FT_Error error = FT_Err_Ok; FT_Face face = FT_FACE( pcf ); FT_Memory memory = face->memory; PCF_Property prop; size_t nn, len; char* strings[4] = { NULL, NULL, NULL, NULL }; size_t lengths[4]; face->style_flags = 0; prop = pcf_find_property( pcf, "SLANT" ); if ( prop && prop->isString && ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' || *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) ) { face->style_flags |= FT_STYLE_FLAG_ITALIC; strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ) ? (char *)"Oblique" : (char *)"Italic"; } prop = pcf_find_property( pcf, "WEIGHT_NAME" ); if ( prop && prop->isString && ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) ) { face->style_flags |= FT_STYLE_FLAG_BOLD; strings[1] = (char*)"Bold"; } prop = pcf_find_property( pcf, "SETWIDTH_NAME" ); if ( prop && prop->isString && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) strings[3] = (char*)( prop->value.atom ); prop = pcf_find_property( pcf, "ADD_STYLE_NAME" ); if ( prop && prop->isString && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) strings[0] = (char*)( prop->value.atom ); for ( len = 0, nn = 0; nn < 4; nn++ ) { lengths[nn] = 0; if ( strings[nn] ) { lengths[nn] = ft_strlen( strings[nn] ); len += lengths[nn] + 1; } } if ( len == 0 ) { strings[0] = (char*)"Regular"; lengths[0] = ft_strlen( strings[0] ); len = lengths[0] + 1; } { char* s; if ( FT_ALLOC( face->style_name, len ) ) return error; s = face->style_name; for ( nn = 0; nn < 4; nn++ ) { char* src = strings[nn]; len = lengths[nn]; if ( src == NULL ) continue; /* separate elements with a space */ if ( s != face->style_name ) *s++ = ' '; ft_memcpy( s, src, len ); /* need to convert spaces to dashes for */ /* add_style_name and setwidth_name */ if ( nn == 0 || nn == 3 ) { size_t mm; for ( mm = 0; mm < len; mm++ ) if ( s[mm] == ' ' ) s[mm] = '-'; } s += len; } *s = 0; } return error; }
DoS Overflow
0
pcf_interpret_style( PCF_Face pcf ) { FT_Error error = FT_Err_Ok; FT_Face face = FT_FACE( pcf ); FT_Memory memory = face->memory; PCF_Property prop; size_t nn, len; char* strings[4] = { NULL, NULL, NULL, NULL }; size_t lengths[4]; face->style_flags = 0; prop = pcf_find_property( pcf, "SLANT" ); if ( prop && prop->isString && ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' || *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) ) { face->style_flags |= FT_STYLE_FLAG_ITALIC; strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ) ? (char *)"Oblique" : (char *)"Italic"; } prop = pcf_find_property( pcf, "WEIGHT_NAME" ); if ( prop && prop->isString && ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) ) { face->style_flags |= FT_STYLE_FLAG_BOLD; strings[1] = (char*)"Bold"; } prop = pcf_find_property( pcf, "SETWIDTH_NAME" ); if ( prop && prop->isString && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) strings[3] = (char*)( prop->value.atom ); prop = pcf_find_property( pcf, "ADD_STYLE_NAME" ); if ( prop && prop->isString && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) strings[0] = (char*)( prop->value.atom ); for ( len = 0, nn = 0; nn < 4; nn++ ) { lengths[nn] = 0; if ( strings[nn] ) { lengths[nn] = ft_strlen( strings[nn] ); len += lengths[nn] + 1; } } if ( len == 0 ) { strings[0] = (char*)"Regular"; lengths[0] = ft_strlen( strings[0] ); len = lengths[0] + 1; } { char* s; if ( FT_ALLOC( face->style_name, len ) ) return error; s = face->style_name; for ( nn = 0; nn < 4; nn++ ) { char* src = strings[nn]; len = lengths[nn]; if ( src == NULL ) continue; /* separate elements with a space */ if ( s != face->style_name ) *s++ = ' '; ft_memcpy( s, src, len ); /* need to convert spaces to dashes for */ /* add_style_name and setwidth_name */ if ( nn == 0 || nn == 3 ) { size_t mm; for ( mm = 0; mm < len; mm++ ) if ( s[mm] == ' ' ) s[mm] = '-'; } s += len; } *s = 0; } return error; }
@@ -830,6 +830,15 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
CWE-189
null
null
5,533
tt_cmap0_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 262 ) FT_INVALID_TOO_SHORT; /* check glyph indices whenever necessary */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt n, idx; p = table + 6; for ( n = 0; n < 256; n++ ) { idx = *p++; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } return FT_Err_Ok; }
DoS Overflow Mem. Corr.
0
tt_cmap0_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 262 ) FT_INVALID_TOO_SHORT; /* check glyph indices whenever necessary */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt n, idx; p = table + 6; for ( n = 0; n < 256; n++ ) { idx = *p++; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } return FT_Err_Ok; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,534
tt_cmap2_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 2; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; }
DoS Overflow Mem. Corr.
0
tt_cmap2_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 2; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,535
tt_cmap2_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; FT_UInt n, max_subs; FT_Byte* keys; /* keys table */ FT_Byte* subs; /* sub-headers */ FT_Byte* glyph_ids; /* glyph ID array */ if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 6 + 512 ) FT_INVALID_TOO_SHORT; keys = table + 6; /* parse keys to compute sub-headers count */ p = keys; max_subs = 0; for ( n = 0; n < 256; n++ ) { FT_UInt idx = TT_NEXT_USHORT( p ); /* value must be multiple of 8 */ if ( valid->level >= FT_VALIDATE_PARANOID && ( idx & 7 ) != 0 ) FT_INVALID_DATA; idx >>= 3; if ( idx > max_subs ) max_subs = idx; } FT_ASSERT( p == table + 518 ); subs = p; glyph_ids = subs + (max_subs + 1) * 8; if ( glyph_ids > valid->limit ) FT_INVALID_TOO_SHORT; /* parse sub-headers */ for ( n = 0; n <= max_subs; n++ ) { FT_UInt first_code, code_count, offset; FT_Int delta; first_code = TT_NEXT_USHORT( p ); code_count = TT_NEXT_USHORT( p ); delta = TT_NEXT_SHORT( p ); offset = TT_NEXT_USHORT( p ); /* many Dynalab fonts have empty sub-headers */ if ( code_count == 0 ) continue; /* check range within 0..255 */ if ( valid->level >= FT_VALIDATE_PARANOID ) { if ( first_code >= 256 || first_code + code_count > 256 ) FT_INVALID_DATA; } /* check offset */ if ( offset != 0 ) { FT_Byte* ids; ids = p - 2 + offset; if ( ids < glyph_ids || ids + code_count*2 > table + length ) FT_INVALID_OFFSET; /* check glyph IDs */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_Byte* limit = p + code_count * 2; FT_UInt idx; for ( ; p < limit; ) { idx = TT_NEXT_USHORT( p ); if ( idx != 0 ) { idx = ( idx + delta ) & 0xFFFFU; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } } } } return FT_Err_Ok; }
DoS Overflow Mem. Corr.
0
tt_cmap2_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; FT_UInt n, max_subs; FT_Byte* keys; /* keys table */ FT_Byte* subs; /* sub-headers */ FT_Byte* glyph_ids; /* glyph ID array */ if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 6 + 512 ) FT_INVALID_TOO_SHORT; keys = table + 6; /* parse keys to compute sub-headers count */ p = keys; max_subs = 0; for ( n = 0; n < 256; n++ ) { FT_UInt idx = TT_NEXT_USHORT( p ); /* value must be multiple of 8 */ if ( valid->level >= FT_VALIDATE_PARANOID && ( idx & 7 ) != 0 ) FT_INVALID_DATA; idx >>= 3; if ( idx > max_subs ) max_subs = idx; } FT_ASSERT( p == table + 518 ); subs = p; glyph_ids = subs + (max_subs + 1) * 8; if ( glyph_ids > valid->limit ) FT_INVALID_TOO_SHORT; /* parse sub-headers */ for ( n = 0; n <= max_subs; n++ ) { FT_UInt first_code, code_count, offset; FT_Int delta; first_code = TT_NEXT_USHORT( p ); code_count = TT_NEXT_USHORT( p ); delta = TT_NEXT_SHORT( p ); offset = TT_NEXT_USHORT( p ); /* many Dynalab fonts have empty sub-headers */ if ( code_count == 0 ) continue; /* check range within 0..255 */ if ( valid->level >= FT_VALIDATE_PARANOID ) { if ( first_code >= 256 || first_code + code_count > 256 ) FT_INVALID_DATA; } /* check offset */ if ( offset != 0 ) { FT_Byte* ids; ids = p - 2 + offset; if ( ids < glyph_ids || ids + code_count*2 > table + length ) FT_INVALID_OFFSET; /* check glyph IDs */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_Byte* limit = p + code_count * 2; FT_UInt idx; for ( ; p < limit; ) { idx = TT_NEXT_USHORT( p ); if ( idx != 0 ) { idx = ( idx + delta ) & 0xFFFFU; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } } } } return FT_Err_Ok; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,536
tt_cmap4_char_map_binary( TT_CMap cmap, FT_UInt32* pcharcode, FT_Bool next ) { FT_UInt num_segs2, start, end, offset; FT_Int delta; FT_UInt max, min, mid, num_segs; FT_UInt charcode = (FT_UInt)*pcharcode; FT_UInt gindex = 0; FT_Byte* p; p = cmap->data + 6; num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 ); if ( !num_segs2 ) return 0; num_segs = num_segs2 >> 1; /* make compiler happy */ mid = num_segs; end = 0xFFFFU; if ( next ) charcode++; min = 0; max = num_segs; /* binary search */ while ( min < max ) { mid = ( min + max ) >> 1; p = cmap->data + 14 + mid * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); if ( charcode < start ) max = mid; else if ( charcode > end ) min = mid + 1; else { p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); /* some fonts have an incorrect last segment; */ /* we have to catch it */ if ( mid >= num_segs - 1 && start == 0xFFFFU && end == 0xFFFFU ) { TT_Face face = (TT_Face)cmap->cmap.charmap.face; FT_Byte* limit = face->cmap_table + face->cmap_size; if ( offset && p + offset + 2 > limit ) { delta = 1; offset = 0; } } /* search the first segment containing `charcode' */ if ( cmap->flags & TT_CMAP_FLAG_OVERLAPPING ) { FT_UInt i; /* call the current segment `max' */ max = mid; if ( offset == 0xFFFFU ) mid = max + 1; /* search in segments before the current segment */ for ( i = max ; i > 0; i-- ) { FT_UInt prev_end; FT_Byte* old_p; old_p = p; p = cmap->data + 14 + ( i - 1 ) * 2; prev_end = TT_PEEK_USHORT( p ); if ( charcode > prev_end ) { p = old_p; break; } end = prev_end; p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); if ( offset != 0xFFFFU ) mid = i - 1; } /* no luck */ if ( mid == max + 1 ) { if ( i != max ) { p = cmap->data + 14 + max * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); } mid = max; /* search in segments after the current segment */ for ( i = max + 1; i < num_segs; i++ ) { FT_UInt next_end, next_start; p = cmap->data + 14 + i * 2; next_end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; next_start = TT_PEEK_USHORT( p ); if ( charcode < next_start ) break; end = next_end; start = next_start; p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); if ( offset != 0xFFFFU ) mid = i; } i--; /* still no luck */ if ( mid == max ) { mid = i; break; } } /* end, start, delta, and offset are for the i'th segment */ if ( mid != i ) { p = cmap->data + 14 + mid * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); } } else { if ( offset == 0xFFFFU ) break; } if ( offset ) { p += offset + ( charcode - start ) * 2; gindex = TT_PEEK_USHORT( p ); if ( gindex != 0 ) gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU; } else gindex = (FT_UInt)( charcode + delta ) & 0xFFFFU; break; } } if ( next ) { TT_CMap4 cmap4 = (TT_CMap4)cmap; /* if `charcode' is not in any segment, then `mid' is */ /* the segment nearest to `charcode' */ /* */ if ( charcode > end ) { mid++; if ( mid == num_segs ) return 0; } if ( tt_cmap4_set_range( cmap4, mid ) ) { if ( gindex ) *pcharcode = charcode; } else { cmap4->cur_charcode = charcode; if ( gindex ) cmap4->cur_gindex = gindex; else { cmap4->cur_charcode = charcode; tt_cmap4_next( cmap4 ); gindex = cmap4->cur_gindex; } if ( gindex ) *pcharcode = cmap4->cur_charcode; } } return gindex; }
DoS Overflow Mem. Corr.
0
tt_cmap4_char_map_binary( TT_CMap cmap, FT_UInt32* pcharcode, FT_Bool next ) { FT_UInt num_segs2, start, end, offset; FT_Int delta; FT_UInt max, min, mid, num_segs; FT_UInt charcode = (FT_UInt)*pcharcode; FT_UInt gindex = 0; FT_Byte* p; p = cmap->data + 6; num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 ); if ( !num_segs2 ) return 0; num_segs = num_segs2 >> 1; /* make compiler happy */ mid = num_segs; end = 0xFFFFU; if ( next ) charcode++; min = 0; max = num_segs; /* binary search */ while ( min < max ) { mid = ( min + max ) >> 1; p = cmap->data + 14 + mid * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); if ( charcode < start ) max = mid; else if ( charcode > end ) min = mid + 1; else { p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); /* some fonts have an incorrect last segment; */ /* we have to catch it */ if ( mid >= num_segs - 1 && start == 0xFFFFU && end == 0xFFFFU ) { TT_Face face = (TT_Face)cmap->cmap.charmap.face; FT_Byte* limit = face->cmap_table + face->cmap_size; if ( offset && p + offset + 2 > limit ) { delta = 1; offset = 0; } } /* search the first segment containing `charcode' */ if ( cmap->flags & TT_CMAP_FLAG_OVERLAPPING ) { FT_UInt i; /* call the current segment `max' */ max = mid; if ( offset == 0xFFFFU ) mid = max + 1; /* search in segments before the current segment */ for ( i = max ; i > 0; i-- ) { FT_UInt prev_end; FT_Byte* old_p; old_p = p; p = cmap->data + 14 + ( i - 1 ) * 2; prev_end = TT_PEEK_USHORT( p ); if ( charcode > prev_end ) { p = old_p; break; } end = prev_end; p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); if ( offset != 0xFFFFU ) mid = i - 1; } /* no luck */ if ( mid == max + 1 ) { if ( i != max ) { p = cmap->data + 14 + max * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); } mid = max; /* search in segments after the current segment */ for ( i = max + 1; i < num_segs; i++ ) { FT_UInt next_end, next_start; p = cmap->data + 14 + i * 2; next_end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; next_start = TT_PEEK_USHORT( p ); if ( charcode < next_start ) break; end = next_end; start = next_start; p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); if ( offset != 0xFFFFU ) mid = i; } i--; /* still no luck */ if ( mid == max ) { mid = i; break; } } /* end, start, delta, and offset are for the i'th segment */ if ( mid != i ) { p = cmap->data + 14 + mid * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); } } else { if ( offset == 0xFFFFU ) break; } if ( offset ) { p += offset + ( charcode - start ) * 2; gindex = TT_PEEK_USHORT( p ); if ( gindex != 0 ) gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU; } else gindex = (FT_UInt)( charcode + delta ) & 0xFFFFU; break; } } if ( next ) { TT_CMap4 cmap4 = (TT_CMap4)cmap; /* if `charcode' is not in any segment, then `mid' is */ /* the segment nearest to `charcode' */ /* */ if ( charcode > end ) { mid++; if ( mid == num_segs ) return 0; } if ( tt_cmap4_set_range( cmap4, mid ) ) { if ( gindex ) *pcharcode = charcode; } else { cmap4->cur_charcode = charcode; if ( gindex ) cmap4->cur_gindex = gindex; else { cmap4->cur_charcode = charcode; tt_cmap4_next( cmap4 ); gindex = cmap4->cur_gindex; } if ( gindex ) *pcharcode = cmap4->cur_charcode; } } return gindex; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,537
tt_cmap4_init( TT_CMap4 cmap, FT_Byte* table ) { FT_Byte* p; cmap->cmap.data = table; p = table + 6; cmap->num_ranges = FT_PEEK_USHORT( p ) >> 1; cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL; cmap->cur_gindex = 0; return FT_Err_Ok; }
DoS Overflow Mem. Corr.
0
tt_cmap4_init( TT_CMap4 cmap, FT_Byte* table ) { FT_Byte* p; cmap->cmap.data = table; p = table + 6; cmap->num_ranges = FT_PEEK_USHORT( p ) >> 1; cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL; cmap->cur_gindex = 0; return FT_Err_Ok; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,538
tt_cmap4_next( TT_CMap4 cmap ) { FT_UInt charcode; if ( cmap->cur_charcode >= 0xFFFFUL ) goto Fail; charcode = (FT_UInt)cmap->cur_charcode + 1; if ( charcode < cmap->cur_start ) charcode = cmap->cur_start; for ( ;; ) { FT_Byte* values = cmap->cur_values; FT_UInt end = cmap->cur_end; FT_Int delta = cmap->cur_delta; if ( charcode <= end ) { if ( values ) { FT_Byte* p = values + 2 * ( charcode - cmap->cur_start ); do { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex != 0 ) { gindex = (FT_UInt)( ( gindex + delta ) & 0xFFFFU ); if ( gindex != 0 ) { cmap->cur_charcode = charcode; cmap->cur_gindex = gindex; return; } } } while ( ++charcode <= end ); } else { do { FT_UInt gindex = (FT_UInt)( ( charcode + delta ) & 0xFFFFU ); if ( gindex != 0 ) { cmap->cur_charcode = charcode; cmap->cur_gindex = gindex; return; } } while ( ++charcode <= end ); } } /* we need to find another range */ if ( tt_cmap4_set_range( cmap, cmap->cur_range + 1 ) < 0 ) break; if ( charcode < cmap->cur_start ) charcode = cmap->cur_start; } Fail: cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL; cmap->cur_gindex = 0; }
DoS Overflow Mem. Corr.
0
tt_cmap4_next( TT_CMap4 cmap ) { FT_UInt charcode; if ( cmap->cur_charcode >= 0xFFFFUL ) goto Fail; charcode = (FT_UInt)cmap->cur_charcode + 1; if ( charcode < cmap->cur_start ) charcode = cmap->cur_start; for ( ;; ) { FT_Byte* values = cmap->cur_values; FT_UInt end = cmap->cur_end; FT_Int delta = cmap->cur_delta; if ( charcode <= end ) { if ( values ) { FT_Byte* p = values + 2 * ( charcode - cmap->cur_start ); do { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex != 0 ) { gindex = (FT_UInt)( ( gindex + delta ) & 0xFFFFU ); if ( gindex != 0 ) { cmap->cur_charcode = charcode; cmap->cur_gindex = gindex; return; } } } while ( ++charcode <= end ); } else { do { FT_UInt gindex = (FT_UInt)( ( charcode + delta ) & 0xFFFFU ); if ( gindex != 0 ) { cmap->cur_charcode = charcode; cmap->cur_gindex = gindex; return; } } while ( ++charcode <= end ); } } /* we need to find another range */ if ( tt_cmap4_set_range( cmap, cmap->cur_range + 1 ) < 0 ) break; if ( charcode < cmap->cur_start ) charcode = cmap->cur_start; } Fail: cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL; cmap->cur_gindex = 0; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,539
tt_cmap4_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; FT_Byte *ends, *starts, *offsets, *deltas, *glyph_ids; FT_UInt num_segs; FT_Error error = FT_Err_Ok; if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( length < 16 ) FT_INVALID_TOO_SHORT; /* in certain fonts, the `length' field is invalid and goes */ /* out of bound. We try to correct this here... */ if ( table + length > valid->limit ) { if ( valid->level >= FT_VALIDATE_TIGHT ) FT_INVALID_TOO_SHORT; length = (FT_UInt)( valid->limit - table ); } p = table + 6; num_segs = TT_NEXT_USHORT( p ); /* read segCountX2 */ if ( valid->level >= FT_VALIDATE_PARANOID ) { /* check that we have an even value here */ if ( num_segs & 1 ) FT_INVALID_DATA; } num_segs /= 2; if ( length < 16 + num_segs * 2 * 4 ) FT_INVALID_TOO_SHORT; /* check the search parameters - even though we never use them */ /* */ if ( valid->level >= FT_VALIDATE_PARANOID ) { /* check the values of `searchRange', `entrySelector', `rangeShift' */ FT_UInt search_range = TT_NEXT_USHORT( p ); FT_UInt entry_selector = TT_NEXT_USHORT( p ); FT_UInt range_shift = TT_NEXT_USHORT( p ); if ( ( search_range | range_shift ) & 1 ) /* must be even values */ FT_INVALID_DATA; search_range /= 2; range_shift /= 2; /* `search range' is the greatest power of 2 that is <= num_segs */ if ( search_range > num_segs || search_range * 2 < num_segs || search_range + range_shift != num_segs || search_range != ( 1U << entry_selector ) ) FT_INVALID_DATA; } ends = table + 14; starts = table + 16 + num_segs * 2; deltas = starts + num_segs * 2; offsets = deltas + num_segs * 2; glyph_ids = offsets + num_segs * 2; /* check last segment; its end count value must be 0xFFFF */ if ( valid->level >= FT_VALIDATE_PARANOID ) { p = ends + ( num_segs - 1 ) * 2; if ( TT_PEEK_USHORT( p ) != 0xFFFFU ) FT_INVALID_DATA; } { FT_UInt start, end, offset, n; FT_UInt last_start = 0, last_end = 0; FT_Int delta; FT_Byte* p_start = starts; FT_Byte* p_end = ends; FT_Byte* p_delta = deltas; FT_Byte* p_offset = offsets; for ( n = 0; n < num_segs; n++ ) { p = p_offset; start = TT_NEXT_USHORT( p_start ); end = TT_NEXT_USHORT( p_end ); delta = TT_NEXT_SHORT( p_delta ); offset = TT_NEXT_USHORT( p_offset ); if ( start > end ) FT_INVALID_DATA; /* this test should be performed at default validation level; */ /* unfortunately, some popular Asian fonts have overlapping */ /* ranges in their charmaps */ /* */ if ( start <= last_end && n > 0 ) { if ( valid->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; else { /* allow overlapping segments, provided their start points */ /* and end points, respectively, are in ascending order */ /* */ if ( last_start > start || last_end > end ) error |= TT_CMAP_FLAG_UNSORTED; else error |= TT_CMAP_FLAG_OVERLAPPING; } } if ( offset && offset != 0xFFFFU ) { p += offset; /* start of glyph ID array */ /* check that we point within the glyph IDs table only */ if ( valid->level >= FT_VALIDATE_TIGHT ) { if ( p < glyph_ids || p + ( end - start + 1 ) * 2 > table + length ) FT_INVALID_DATA; } /* Some fonts handle the last segment incorrectly. In */ /* theory, 0xFFFF might point to an ordinary glyph -- */ /* a cmap 4 is versatile and could be used for any */ /* encoding, not only Unicode. However, reality shows */ /* that far too many fonts are sloppy and incorrectly */ /* set all fields but `start' and `end' for the last */ /* segment if it contains only a single character. */ /* */ /* We thus omit the test here, delaying it to the */ /* routines which actually access the cmap. */ else if ( n != num_segs - 1 || !( start == 0xFFFFU && end == 0xFFFFU ) ) { if ( p < glyph_ids || p + ( end - start + 1 ) * 2 > valid->limit ) FT_INVALID_DATA; } /* check glyph indices within the segment range */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt i, idx; for ( i = start; i < end; i++ ) { idx = FT_NEXT_USHORT( p ); if ( idx != 0 ) { idx = (FT_UInt)( idx + delta ) & 0xFFFFU; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } } } else if ( offset == 0xFFFFU ) { /* some fonts (erroneously?) use a range offset of 0xFFFF */ /* to mean missing glyph in cmap table */ /* */ if ( valid->level >= FT_VALIDATE_PARANOID || n != num_segs - 1 || !( start == 0xFFFFU && end == 0xFFFFU ) ) FT_INVALID_DATA; } last_start = start; last_end = end; } } return error; }
DoS Overflow Mem. Corr.
0
tt_cmap4_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; FT_Byte *ends, *starts, *offsets, *deltas, *glyph_ids; FT_UInt num_segs; FT_Error error = FT_Err_Ok; if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( length < 16 ) FT_INVALID_TOO_SHORT; /* in certain fonts, the `length' field is invalid and goes */ /* out of bound. We try to correct this here... */ if ( table + length > valid->limit ) { if ( valid->level >= FT_VALIDATE_TIGHT ) FT_INVALID_TOO_SHORT; length = (FT_UInt)( valid->limit - table ); } p = table + 6; num_segs = TT_NEXT_USHORT( p ); /* read segCountX2 */ if ( valid->level >= FT_VALIDATE_PARANOID ) { /* check that we have an even value here */ if ( num_segs & 1 ) FT_INVALID_DATA; } num_segs /= 2; if ( length < 16 + num_segs * 2 * 4 ) FT_INVALID_TOO_SHORT; /* check the search parameters - even though we never use them */ /* */ if ( valid->level >= FT_VALIDATE_PARANOID ) { /* check the values of `searchRange', `entrySelector', `rangeShift' */ FT_UInt search_range = TT_NEXT_USHORT( p ); FT_UInt entry_selector = TT_NEXT_USHORT( p ); FT_UInt range_shift = TT_NEXT_USHORT( p ); if ( ( search_range | range_shift ) & 1 ) /* must be even values */ FT_INVALID_DATA; search_range /= 2; range_shift /= 2; /* `search range' is the greatest power of 2 that is <= num_segs */ if ( search_range > num_segs || search_range * 2 < num_segs || search_range + range_shift != num_segs || search_range != ( 1U << entry_selector ) ) FT_INVALID_DATA; } ends = table + 14; starts = table + 16 + num_segs * 2; deltas = starts + num_segs * 2; offsets = deltas + num_segs * 2; glyph_ids = offsets + num_segs * 2; /* check last segment; its end count value must be 0xFFFF */ if ( valid->level >= FT_VALIDATE_PARANOID ) { p = ends + ( num_segs - 1 ) * 2; if ( TT_PEEK_USHORT( p ) != 0xFFFFU ) FT_INVALID_DATA; } { FT_UInt start, end, offset, n; FT_UInt last_start = 0, last_end = 0; FT_Int delta; FT_Byte* p_start = starts; FT_Byte* p_end = ends; FT_Byte* p_delta = deltas; FT_Byte* p_offset = offsets; for ( n = 0; n < num_segs; n++ ) { p = p_offset; start = TT_NEXT_USHORT( p_start ); end = TT_NEXT_USHORT( p_end ); delta = TT_NEXT_SHORT( p_delta ); offset = TT_NEXT_USHORT( p_offset ); if ( start > end ) FT_INVALID_DATA; /* this test should be performed at default validation level; */ /* unfortunately, some popular Asian fonts have overlapping */ /* ranges in their charmaps */ /* */ if ( start <= last_end && n > 0 ) { if ( valid->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; else { /* allow overlapping segments, provided their start points */ /* and end points, respectively, are in ascending order */ /* */ if ( last_start > start || last_end > end ) error |= TT_CMAP_FLAG_UNSORTED; else error |= TT_CMAP_FLAG_OVERLAPPING; } } if ( offset && offset != 0xFFFFU ) { p += offset; /* start of glyph ID array */ /* check that we point within the glyph IDs table only */ if ( valid->level >= FT_VALIDATE_TIGHT ) { if ( p < glyph_ids || p + ( end - start + 1 ) * 2 > table + length ) FT_INVALID_DATA; } /* Some fonts handle the last segment incorrectly. In */ /* theory, 0xFFFF might point to an ordinary glyph -- */ /* a cmap 4 is versatile and could be used for any */ /* encoding, not only Unicode. However, reality shows */ /* that far too many fonts are sloppy and incorrectly */ /* set all fields but `start' and `end' for the last */ /* segment if it contains only a single character. */ /* */ /* We thus omit the test here, delaying it to the */ /* routines which actually access the cmap. */ else if ( n != num_segs - 1 || !( start == 0xFFFFU && end == 0xFFFFU ) ) { if ( p < glyph_ids || p + ( end - start + 1 ) * 2 > valid->limit ) FT_INVALID_DATA; } /* check glyph indices within the segment range */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt i, idx; for ( i = start; i < end; i++ ) { idx = FT_NEXT_USHORT( p ); if ( idx != 0 ) { idx = (FT_UInt)( idx + delta ) & 0xFFFFU; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } } } else if ( offset == 0xFFFFU ) { /* some fonts (erroneously?) use a range offset of 0xFFFF */ /* to mean missing glyph in cmap table */ /* */ if ( valid->level >= FT_VALIDATE_PARANOID || n != num_segs - 1 || !( start == 0xFFFFU && end == 0xFFFFU ) ) FT_INVALID_DATA; } last_start = start; last_end = end; } } return error; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,540
tt_cmap6_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 6; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; }
DoS Overflow Mem. Corr.
0
tt_cmap6_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 6; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,541
tt_cmap6_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length, count; if ( table + 10 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; length = TT_NEXT_USHORT( p ); p = table + 8; /* skip language and start index */ count = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 10 + count * 2 ) FT_INVALID_TOO_SHORT; /* check glyph indices */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt gindex; for ( ; count > 0; count-- ) { gindex = TT_NEXT_USHORT( p ); if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } return FT_Err_Ok; }
DoS Overflow Mem. Corr.
0
tt_cmap6_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length, count; if ( table + 10 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; length = TT_NEXT_USHORT( p ); p = table + 8; /* skip language and start index */ count = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 10 + count * 2 ) FT_INVALID_TOO_SHORT; /* check glyph indices */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt gindex; for ( ; count > 0; count-- ) { gindex = TT_NEXT_USHORT( p ); if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } return FT_Err_Ok; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,542
tt_cmap_init( TT_CMap cmap, FT_Byte* table ) { cmap->data = table; return FT_Err_Ok; }
DoS Overflow Mem. Corr.
0
tt_cmap_init( TT_CMap cmap, FT_Byte* table ) { cmap->data = table; return FT_Err_Ok; }
@@ -1669,7 +1669,8 @@ p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); - if ( p + num_groups * 12 > valid->limit ) + /* p + num_groups * 12 > valid->limit ? */ + if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -1694,7 +1695,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); @@ -1892,7 +1898,9 @@ count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 20 + count * 2 ) + /* length < 20 + count * 2 ? */ + length < 20 || + ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ @@ -2079,7 +2087,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2101,7 +2111,12 @@ if ( valid->level >= FT_VALIDATE_TIGHT ) { - if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ) + FT_UInt32 d = end - start; + + + /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ + if ( d > TT_VALID_GLYPH_COUNT( valid ) || + start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } @@ -2401,7 +2416,9 @@ num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 16 + 12 * num_groups ) + /* length < 16 + 12 * num_groups ? */ + length < 16 || + ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ @@ -2787,7 +2804,9 @@ num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || - length < 10 + 11 * num_selectors ) + /* length < 10 + 11 * num_selectors ? */ + length < 10 || + ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ @@ -2823,7 +2842,8 @@ FT_ULong lastBase = 0; - if ( defp + numRanges * 4 > valid->limit ) + /* defp + numRanges * 4 > valid->limit ? */ + if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; ++i ) @@ -2850,7 +2870,8 @@ FT_ULong i, lastUni = 0; - if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ) + /* numMappings * 4 > (FT_ULong)( valid->limit - ndp ) ? */ + if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; ++i )
CWE-125
null
null
5,543
sfnt_find_encoding( int platform_id, int encoding_id ) { typedef struct TEncoding_ { int platform_id; int encoding_id; FT_Encoding encoding; } TEncoding; static const TEncoding tt_encodings[] = { { TT_PLATFORM_ISO, -1, FT_ENCODING_UNICODE }, { TT_PLATFORM_APPLE_UNICODE, -1, FT_ENCODING_UNICODE }, { TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, FT_ENCODING_APPLE_ROMAN }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, FT_ENCODING_MS_SYMBOL }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_UCS_4, FT_ENCODING_UNICODE }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, FT_ENCODING_UNICODE }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, FT_ENCODING_SJIS }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_GB2312, FT_ENCODING_GB2312 }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, FT_ENCODING_BIG5 }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, FT_ENCODING_WANSUNG }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, FT_ENCODING_JOHAB } }; const TEncoding *cur, *limit; cur = tt_encodings; limit = cur + sizeof ( tt_encodings ) / sizeof ( tt_encodings[0] ); for ( ; cur < limit; cur++ ) { if ( cur->platform_id == platform_id ) { if ( cur->encoding_id == encoding_id || cur->encoding_id == -1 ) return cur->encoding; } } return FT_ENCODING_NONE; }
DoS Overflow
0
sfnt_find_encoding( int platform_id, int encoding_id ) { typedef struct TEncoding_ { int platform_id; int encoding_id; FT_Encoding encoding; } TEncoding; static const TEncoding tt_encodings[] = { { TT_PLATFORM_ISO, -1, FT_ENCODING_UNICODE }, { TT_PLATFORM_APPLE_UNICODE, -1, FT_ENCODING_UNICODE }, { TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, FT_ENCODING_APPLE_ROMAN }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, FT_ENCODING_MS_SYMBOL }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_UCS_4, FT_ENCODING_UNICODE }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, FT_ENCODING_UNICODE }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, FT_ENCODING_SJIS }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_GB2312, FT_ENCODING_GB2312 }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, FT_ENCODING_BIG5 }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, FT_ENCODING_WANSUNG }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, FT_ENCODING_JOHAB } }; const TEncoding *cur, *limit; cur = tt_encodings; limit = cur + sizeof ( tt_encodings ) / sizeof ( tt_encodings[0] ); for ( ; cur < limit; cur++ ) { if ( cur->platform_id == platform_id ) { if ( cur->encoding_id == encoding_id || cur->encoding_id == -1 ) return cur->encoding; } } return FT_ENCODING_NONE; }
@@ -567,8 +567,10 @@ if ( table->Offset != woff_offset || - table->Offset + table->CompLength > woff.length || - sfnt_offset + table->OrigLength > woff.totalSfntSize || + table->CompLength > woff.length || + table->Offset > woff.length - table->CompLength || + table->OrigLength > woff.totalSfntSize || + sfnt_offset > woff.totalSfntSize - table->OrigLength || table->CompLength > table->OrigLength ) { error = FT_THROW( Invalid_Table );
CWE-119
null
null
5,544
sfnt_stream_close( FT_Stream stream ) { FT_Memory memory = stream->memory; FT_FREE( stream->base ); stream->size = 0; stream->base = 0; stream->close = 0; }
DoS Overflow
0
sfnt_stream_close( FT_Stream stream ) { FT_Memory memory = stream->memory; FT_FREE( stream->base ); stream->size = 0; stream->base = 0; stream->close = 0; }
@@ -567,8 +567,10 @@ if ( table->Offset != woff_offset || - table->Offset + table->CompLength > woff.length || - sfnt_offset + table->OrigLength > woff.totalSfntSize || + table->CompLength > woff.length || + table->Offset > woff.length - table->CompLength || + table->OrigLength > woff.totalSfntSize || + sfnt_offset > woff.totalSfntSize - table->OrigLength || table->CompLength > table->OrigLength ) { error = FT_THROW( Invalid_Table );
CWE-119
null
null
5,545
tt_face_get_name( TT_Face face, FT_UShort nameid, FT_String** name ) { FT_Memory memory = face->root.memory; FT_Error error = FT_Err_Ok; FT_String* result = NULL; FT_UShort n; TT_NameEntryRec* rec; FT_Int found_apple = -1; FT_Int found_apple_roman = -1; FT_Int found_apple_english = -1; FT_Int found_win = -1; FT_Int found_unicode = -1; FT_Bool is_english = 0; TT_NameEntry_ConvertFunc convert; FT_ASSERT( name ); rec = face->name_table.names; for ( n = 0; n < face->num_names; n++, rec++ ) { /* According to the OpenType 1.3 specification, only Microsoft or */ /* Apple platform IDs might be used in the `name' table. The */ /* `Unicode' platform is reserved for the `cmap' table, and the */ /* `ISO' one is deprecated. */ /* */ /* However, the Apple TrueType specification doesn't say the same */ /* thing and goes to suggest that all Unicode `name' table entries */ /* should be coded in UTF-16 (in big-endian format I suppose). */ /* */ if ( rec->nameID == nameid && rec->stringLength > 0 ) { switch ( rec->platformID ) { case TT_PLATFORM_APPLE_UNICODE: case TT_PLATFORM_ISO: /* there is `languageID' to check there. We should use this */ /* field only as a last solution when nothing else is */ /* available. */ /* */ found_unicode = n; break; case TT_PLATFORM_MACINTOSH: /* This is a bit special because some fonts will use either */ /* an English language id, or a Roman encoding id, to indicate */ /* the English version of its font name. */ /* */ if ( rec->languageID == TT_MAC_LANGID_ENGLISH ) found_apple_english = n; else if ( rec->encodingID == TT_MAC_ID_ROMAN ) found_apple_roman = n; break; case TT_PLATFORM_MICROSOFT: /* we only take a non-English name when there is nothing */ /* else available in the font */ /* */ if ( found_win == -1 || ( rec->languageID & 0x3FF ) == 0x009 ) { switch ( rec->encodingID ) { case TT_MS_ID_SYMBOL_CS: case TT_MS_ID_UNICODE_CS: case TT_MS_ID_UCS_4: is_english = FT_BOOL( ( rec->languageID & 0x3FF ) == 0x009 ); found_win = n; break; default: ; } } break; default: ; } } } found_apple = found_apple_roman; if ( found_apple_english >= 0 ) found_apple = found_apple_english; /* some fonts contain invalid Unicode or Macintosh formatted entries; */ /* we will thus favor names encoded in Windows formats if available */ /* (provided it is an English name) */ /* */ convert = NULL; if ( found_win >= 0 && !( found_apple >= 0 && !is_english ) ) { rec = face->name_table.names + found_win; switch ( rec->encodingID ) { /* all Unicode strings are encoded using UTF-16BE */ case TT_MS_ID_UNICODE_CS: case TT_MS_ID_SYMBOL_CS: convert = tt_name_entry_ascii_from_utf16; break; case TT_MS_ID_UCS_4: /* Apparently, if this value is found in a name table entry, it is */ /* documented as `full Unicode repertoire'. Experience with the */ /* MsGothic font shipped with Windows Vista shows that this really */ /* means UTF-16 encoded names (UCS-4 values are only used within */ /* charmaps). */ convert = tt_name_entry_ascii_from_utf16; break; default: ; } } else if ( found_apple >= 0 ) { rec = face->name_table.names + found_apple; convert = tt_name_entry_ascii_from_other; } else if ( found_unicode >= 0 ) { rec = face->name_table.names + found_unicode; convert = tt_name_entry_ascii_from_utf16; } if ( rec && convert ) { if ( rec->string == NULL ) { FT_Stream stream = face->name_table.stream; if ( FT_QNEW_ARRAY ( rec->string, rec->stringLength ) || FT_STREAM_SEEK( rec->stringOffset ) || FT_STREAM_READ( rec->string, rec->stringLength ) ) { FT_FREE( rec->string ); rec->stringLength = 0; result = NULL; goto Exit; } } result = convert( rec, memory ); } Exit: *name = result; return error; }
DoS Overflow
0
tt_face_get_name( TT_Face face, FT_UShort nameid, FT_String** name ) { FT_Memory memory = face->root.memory; FT_Error error = FT_Err_Ok; FT_String* result = NULL; FT_UShort n; TT_NameEntryRec* rec; FT_Int found_apple = -1; FT_Int found_apple_roman = -1; FT_Int found_apple_english = -1; FT_Int found_win = -1; FT_Int found_unicode = -1; FT_Bool is_english = 0; TT_NameEntry_ConvertFunc convert; FT_ASSERT( name ); rec = face->name_table.names; for ( n = 0; n < face->num_names; n++, rec++ ) { /* According to the OpenType 1.3 specification, only Microsoft or */ /* Apple platform IDs might be used in the `name' table. The */ /* `Unicode' platform is reserved for the `cmap' table, and the */ /* `ISO' one is deprecated. */ /* */ /* However, the Apple TrueType specification doesn't say the same */ /* thing and goes to suggest that all Unicode `name' table entries */ /* should be coded in UTF-16 (in big-endian format I suppose). */ /* */ if ( rec->nameID == nameid && rec->stringLength > 0 ) { switch ( rec->platformID ) { case TT_PLATFORM_APPLE_UNICODE: case TT_PLATFORM_ISO: /* there is `languageID' to check there. We should use this */ /* field only as a last solution when nothing else is */ /* available. */ /* */ found_unicode = n; break; case TT_PLATFORM_MACINTOSH: /* This is a bit special because some fonts will use either */ /* an English language id, or a Roman encoding id, to indicate */ /* the English version of its font name. */ /* */ if ( rec->languageID == TT_MAC_LANGID_ENGLISH ) found_apple_english = n; else if ( rec->encodingID == TT_MAC_ID_ROMAN ) found_apple_roman = n; break; case TT_PLATFORM_MICROSOFT: /* we only take a non-English name when there is nothing */ /* else available in the font */ /* */ if ( found_win == -1 || ( rec->languageID & 0x3FF ) == 0x009 ) { switch ( rec->encodingID ) { case TT_MS_ID_SYMBOL_CS: case TT_MS_ID_UNICODE_CS: case TT_MS_ID_UCS_4: is_english = FT_BOOL( ( rec->languageID & 0x3FF ) == 0x009 ); found_win = n; break; default: ; } } break; default: ; } } } found_apple = found_apple_roman; if ( found_apple_english >= 0 ) found_apple = found_apple_english; /* some fonts contain invalid Unicode or Macintosh formatted entries; */ /* we will thus favor names encoded in Windows formats if available */ /* (provided it is an English name) */ /* */ convert = NULL; if ( found_win >= 0 && !( found_apple >= 0 && !is_english ) ) { rec = face->name_table.names + found_win; switch ( rec->encodingID ) { /* all Unicode strings are encoded using UTF-16BE */ case TT_MS_ID_UNICODE_CS: case TT_MS_ID_SYMBOL_CS: convert = tt_name_entry_ascii_from_utf16; break; case TT_MS_ID_UCS_4: /* Apparently, if this value is found in a name table entry, it is */ /* documented as `full Unicode repertoire'. Experience with the */ /* MsGothic font shipped with Windows Vista shows that this really */ /* means UTF-16 encoded names (UCS-4 values are only used within */ /* charmaps). */ convert = tt_name_entry_ascii_from_utf16; break; default: ; } } else if ( found_apple >= 0 ) { rec = face->name_table.names + found_apple; convert = tt_name_entry_ascii_from_other; } else if ( found_unicode >= 0 ) { rec = face->name_table.names + found_unicode; convert = tt_name_entry_ascii_from_utf16; } if ( rec && convert ) { if ( rec->string == NULL ) { FT_Stream stream = face->name_table.stream; if ( FT_QNEW_ARRAY ( rec->string, rec->stringLength ) || FT_STREAM_SEEK( rec->stringOffset ) || FT_STREAM_READ( rec->string, rec->stringLength ) ) { FT_FREE( rec->string ); rec->stringLength = 0; result = NULL; goto Exit; } } result = convert( rec, memory ); } Exit: *name = result; return error; }
@@ -567,8 +567,10 @@ if ( table->Offset != woff_offset || - table->Offset + table->CompLength > woff.length || - sfnt_offset + table->OrigLength > woff.totalSfntSize || + table->CompLength > woff.length || + table->Offset > woff.length - table->CompLength || + table->OrigLength > woff.totalSfntSize || + sfnt_offset > woff.totalSfntSize - table->OrigLength || table->CompLength > table->OrigLength ) { error = FT_THROW( Invalid_Table );
CWE-119
null
null
5,546
tt_name_entry_ascii_from_other( TT_NameEntry entry, FT_Memory memory ) { FT_String* string = NULL; FT_UInt len, code, n; FT_Byte* read = (FT_Byte*)entry->string; FT_Error error; len = (FT_UInt)entry->stringLength; if ( FT_NEW_ARRAY( string, len + 1 ) ) return NULL; for ( n = 0; n < len; n++ ) { code = *read++; if ( code == 0 ) break; if ( code < 32 || code > 127 ) code = '?'; string[n] = (char)code; } string[n] = 0; return string; }
DoS Overflow
0
tt_name_entry_ascii_from_other( TT_NameEntry entry, FT_Memory memory ) { FT_String* string = NULL; FT_UInt len, code, n; FT_Byte* read = (FT_Byte*)entry->string; FT_Error error; len = (FT_UInt)entry->stringLength; if ( FT_NEW_ARRAY( string, len + 1 ) ) return NULL; for ( n = 0; n < len; n++ ) { code = *read++; if ( code == 0 ) break; if ( code < 32 || code > 127 ) code = '?'; string[n] = (char)code; } string[n] = 0; return string; }
@@ -567,8 +567,10 @@ if ( table->Offset != woff_offset || - table->Offset + table->CompLength > woff.length || - sfnt_offset + table->OrigLength > woff.totalSfntSize || + table->CompLength > woff.length || + table->Offset > woff.length - table->CompLength || + table->OrigLength > woff.totalSfntSize || + sfnt_offset > woff.totalSfntSize - table->OrigLength || table->CompLength > table->OrigLength ) { error = FT_THROW( Invalid_Table );
CWE-119
null
null
5,547
tt_name_entry_ascii_from_utf16( TT_NameEntry entry, FT_Memory memory ) { FT_String* string = NULL; FT_UInt len, code, n; FT_Byte* read = (FT_Byte*)entry->string; FT_Error error; len = (FT_UInt)entry->stringLength / 2; if ( FT_NEW_ARRAY( string, len + 1 ) ) return NULL; for ( n = 0; n < len; n++ ) { code = FT_NEXT_USHORT( read ); if ( code == 0 ) break; if ( code < 32 || code > 127 ) code = '?'; string[n] = (char)code; } string[n] = 0; return string; }
DoS Overflow
0
tt_name_entry_ascii_from_utf16( TT_NameEntry entry, FT_Memory memory ) { FT_String* string = NULL; FT_UInt len, code, n; FT_Byte* read = (FT_Byte*)entry->string; FT_Error error; len = (FT_UInt)entry->stringLength / 2; if ( FT_NEW_ARRAY( string, len + 1 ) ) return NULL; for ( n = 0; n < len; n++ ) { code = FT_NEXT_USHORT( read ); if ( code == 0 ) break; if ( code < 32 || code > 127 ) code = '?'; string[n] = (char)code; } string[n] = 0; return string; }
@@ -567,8 +567,10 @@ if ( table->Offset != woff_offset || - table->Offset + table->CompLength > woff.length || - sfnt_offset + table->OrigLength > woff.totalSfntSize || + table->CompLength > woff.length || + table->Offset > woff.length - table->CompLength || + table->OrigLength > woff.totalSfntSize || + sfnt_offset > woff.totalSfntSize - table->OrigLength || table->CompLength > table->OrigLength ) { error = FT_THROW( Invalid_Table );
CWE-119
null
null
5,548
tt_face_free_sbit( TT_Face face ) { FT_Stream stream = face->root.stream; FT_FRAME_RELEASE( face->sbit_table ); face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; face->sbit_num_strikes = 0; }
DoS Overflow
0
tt_face_free_sbit( TT_Face face ) { FT_Stream stream = face->root.stream; FT_FRAME_RELEASE( face->sbit_table ); face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; face->sbit_num_strikes = 0; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,549
tt_face_load_sbit( TT_Face face, FT_Stream stream ) { FT_Error error; FT_ULong table_size; face->sbit_table = NULL; face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; face->sbit_num_strikes = 0; error = face->goto_table( face, TTAG_CBLC, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_CBLC; else { error = face->goto_table( face, TTAG_EBLC, stream, &table_size ); if ( error ) error = face->goto_table( face, TTAG_bloc, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_EBLC; } if ( error ) { error = face->goto_table( face, TTAG_sbix, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_SBIX; } if ( error ) goto Exit; if ( table_size < 8 ) { FT_ERROR(( "tt_face_load_sbit_strikes: table too short\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { FT_Byte* p; FT_Fixed version; FT_ULong num_strikes; FT_UInt count; if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) ) goto Exit; face->sbit_table_size = table_size; p = face->sbit_table; version = FT_NEXT_ULONG( p ); num_strikes = FT_NEXT_ULONG( p ); if ( ( version & 0xFFFF0000UL ) != 0x00020000UL ) { error = FT_THROW( Unknown_File_Format ); goto Exit; } if ( num_strikes >= 0x10000UL ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* * Count the number of strikes available in the table. We are a bit * paranoid there and don't trust the data. */ count = (FT_UInt)num_strikes; if ( 8 + 48UL * count > table_size ) count = (FT_UInt)( ( table_size - 8 ) / 48 ); face->sbit_num_strikes = count; } break; case TT_SBIT_TABLE_TYPE_SBIX: { FT_UShort version; FT_UShort flags; FT_ULong num_strikes; FT_UInt count; if ( FT_FRAME_ENTER( 8 ) ) goto Exit; version = FT_GET_USHORT(); flags = FT_GET_USHORT(); num_strikes = FT_GET_ULONG(); FT_FRAME_EXIT(); if ( version < 1 ) { error = FT_THROW( Unknown_File_Format ); goto Exit; } /* Bit 0 must always be `1'. */ /* Bit 1 controls the overlay of bitmaps with outlines. */ /* All other bits should be zero. */ if ( !( flags == 1 || flags == 3 ) || num_strikes >= 0x10000UL ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* we currently don't support bit 1; however, it is better to */ /* draw at least something... */ if ( flags == 3 ) FT_TRACE1(( "tt_face_load_sbit_strikes:" " sbix overlay not supported yet\n" " " " expect bad rendering results\n" )); /* * Count the number of strikes available in the table. We are a bit * paranoid there and don't trust the data. */ count = (FT_UInt)num_strikes; if ( 8 + 4UL * count > table_size ) count = (FT_UInt)( ( table_size - 8 ) / 4 ); if ( FT_STREAM_SEEK( FT_STREAM_POS() - 8 ) ) goto Exit; face->sbit_table_size = 8 + count * 4; if ( FT_FRAME_EXTRACT( face->sbit_table_size, face->sbit_table ) ) goto Exit; face->sbit_num_strikes = count; } break; default: error = FT_THROW( Unknown_File_Format ); break; } if ( !error ) FT_TRACE3(( "sbit_num_strikes: %u\n", face->sbit_num_strikes )); return FT_Err_Ok; Exit: if ( error ) { if ( face->sbit_table ) FT_FRAME_RELEASE( face->sbit_table ); face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; } return error; }
DoS Overflow
0
tt_face_load_sbit( TT_Face face, FT_Stream stream ) { FT_Error error; FT_ULong table_size; face->sbit_table = NULL; face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; face->sbit_num_strikes = 0; error = face->goto_table( face, TTAG_CBLC, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_CBLC; else { error = face->goto_table( face, TTAG_EBLC, stream, &table_size ); if ( error ) error = face->goto_table( face, TTAG_bloc, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_EBLC; } if ( error ) { error = face->goto_table( face, TTAG_sbix, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_SBIX; } if ( error ) goto Exit; if ( table_size < 8 ) { FT_ERROR(( "tt_face_load_sbit_strikes: table too short\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { FT_Byte* p; FT_Fixed version; FT_ULong num_strikes; FT_UInt count; if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) ) goto Exit; face->sbit_table_size = table_size; p = face->sbit_table; version = FT_NEXT_ULONG( p ); num_strikes = FT_NEXT_ULONG( p ); if ( ( version & 0xFFFF0000UL ) != 0x00020000UL ) { error = FT_THROW( Unknown_File_Format ); goto Exit; } if ( num_strikes >= 0x10000UL ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* * Count the number of strikes available in the table. We are a bit * paranoid there and don't trust the data. */ count = (FT_UInt)num_strikes; if ( 8 + 48UL * count > table_size ) count = (FT_UInt)( ( table_size - 8 ) / 48 ); face->sbit_num_strikes = count; } break; case TT_SBIT_TABLE_TYPE_SBIX: { FT_UShort version; FT_UShort flags; FT_ULong num_strikes; FT_UInt count; if ( FT_FRAME_ENTER( 8 ) ) goto Exit; version = FT_GET_USHORT(); flags = FT_GET_USHORT(); num_strikes = FT_GET_ULONG(); FT_FRAME_EXIT(); if ( version < 1 ) { error = FT_THROW( Unknown_File_Format ); goto Exit; } /* Bit 0 must always be `1'. */ /* Bit 1 controls the overlay of bitmaps with outlines. */ /* All other bits should be zero. */ if ( !( flags == 1 || flags == 3 ) || num_strikes >= 0x10000UL ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* we currently don't support bit 1; however, it is better to */ /* draw at least something... */ if ( flags == 3 ) FT_TRACE1(( "tt_face_load_sbit_strikes:" " sbix overlay not supported yet\n" " " " expect bad rendering results\n" )); /* * Count the number of strikes available in the table. We are a bit * paranoid there and don't trust the data. */ count = (FT_UInt)num_strikes; if ( 8 + 4UL * count > table_size ) count = (FT_UInt)( ( table_size - 8 ) / 4 ); if ( FT_STREAM_SEEK( FT_STREAM_POS() - 8 ) ) goto Exit; face->sbit_table_size = 8 + count * 4; if ( FT_FRAME_EXTRACT( face->sbit_table_size, face->sbit_table ) ) goto Exit; face->sbit_num_strikes = count; } break; default: error = FT_THROW( Unknown_File_Format ); break; } if ( !error ) FT_TRACE3(( "sbit_num_strikes: %u\n", face->sbit_num_strikes )); return FT_Err_Ok; Exit: if ( error ) { if ( face->sbit_table ) FT_FRAME_RELEASE( face->sbit_table ); face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; } return error; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,550
tt_face_load_sbit_image( TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_UInt load_flags, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics ) { FT_Error error = FT_Err_Ok; switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { TT_SBitDecoderRec decoder[1]; error = tt_sbit_decoder_init( decoder, face, strike_index, metrics ); if ( !error ) { error = tt_sbit_decoder_load_image( decoder, glyph_index, 0, 0 ); tt_sbit_decoder_done( decoder ); } } break; case TT_SBIT_TABLE_TYPE_SBIX: error = tt_face_load_sbix_image( face, strike_index, glyph_index, stream, map, metrics ); break; default: error = FT_THROW( Unknown_File_Format ); break; } /* Flatten color bitmaps if color was not requested. */ if ( !error && !( load_flags & FT_LOAD_COLOR ) && map->pixel_mode == FT_PIXEL_MODE_BGRA ) { FT_Bitmap new_map; FT_Library library = face->root.glyph->library; FT_Bitmap_New( &new_map ); /* Convert to 8bit grayscale. */ error = FT_Bitmap_Convert( library, map, &new_map, 1 ); if ( error ) FT_Bitmap_Done( library, &new_map ); else { map->pixel_mode = new_map.pixel_mode; map->pitch = new_map.pitch; map->num_grays = new_map.num_grays; ft_glyphslot_set_bitmap( face->root.glyph, new_map.buffer ); face->root.glyph->internal->flags |= FT_GLYPH_OWN_BITMAP; } } return error; }
DoS Overflow
0
tt_face_load_sbit_image( TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_UInt load_flags, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics ) { FT_Error error = FT_Err_Ok; switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { TT_SBitDecoderRec decoder[1]; error = tt_sbit_decoder_init( decoder, face, strike_index, metrics ); if ( !error ) { error = tt_sbit_decoder_load_image( decoder, glyph_index, 0, 0 ); tt_sbit_decoder_done( decoder ); } } break; case TT_SBIT_TABLE_TYPE_SBIX: error = tt_face_load_sbix_image( face, strike_index, glyph_index, stream, map, metrics ); break; default: error = FT_THROW( Unknown_File_Format ); break; } /* Flatten color bitmaps if color was not requested. */ if ( !error && !( load_flags & FT_LOAD_COLOR ) && map->pixel_mode == FT_PIXEL_MODE_BGRA ) { FT_Bitmap new_map; FT_Library library = face->root.glyph->library; FT_Bitmap_New( &new_map ); /* Convert to 8bit grayscale. */ error = FT_Bitmap_Convert( library, map, &new_map, 1 ); if ( error ) FT_Bitmap_Done( library, &new_map ); else { map->pixel_mode = new_map.pixel_mode; map->pitch = new_map.pitch; map->num_grays = new_map.num_grays; ft_glyphslot_set_bitmap( face->root.glyph, new_map.buffer ); face->root.glyph->internal->flags |= FT_GLYPH_OWN_BITMAP; } } return error; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,551
tt_face_load_sbix_image( TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics ) { FT_UInt sbix_pos, strike_offset, glyph_start, glyph_end; FT_ULong table_size; FT_Int originOffsetX, originOffsetY; FT_Tag graphicType; FT_Int recurse_depth = 0; FT_Error error; FT_Byte* p; FT_UNUSED( map ); metrics->width = 0; metrics->height = 0; p = face->sbit_table + 8 + 4 * strike_index; strike_offset = FT_NEXT_ULONG( p ); error = face->goto_table( face, TTAG_sbix, stream, &table_size ); if ( error ) return error; sbix_pos = FT_STREAM_POS(); retry: if ( glyph_index > (FT_UInt)face->root.num_glyphs ) return FT_THROW( Invalid_Argument ); if ( strike_offset >= table_size || table_size - strike_offset < 4 + glyph_index * 4 + 8 ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( sbix_pos + strike_offset + 4 + glyph_index * 4 ) || FT_FRAME_ENTER( 8 ) ) return error; glyph_start = FT_GET_ULONG(); glyph_end = FT_GET_ULONG(); FT_FRAME_EXIT(); if ( glyph_start == glyph_end ) return FT_THROW( Invalid_Argument ); if ( glyph_start > glyph_end || glyph_end - glyph_start < 8 || table_size - strike_offset < glyph_end ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( sbix_pos + strike_offset + glyph_start ) || FT_FRAME_ENTER( glyph_end - glyph_start ) ) return error; originOffsetX = FT_GET_SHORT(); originOffsetY = FT_GET_SHORT(); graphicType = FT_GET_TAG4(); switch ( graphicType ) { case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ): if ( recurse_depth < 4 ) { glyph_index = FT_GET_USHORT(); FT_FRAME_EXIT(); recurse_depth++; goto retry; } error = FT_THROW( Invalid_File_Format ); break; case FT_MAKE_TAG( 'p', 'n', 'g', ' ' ): #ifdef FT_CONFIG_OPTION_USE_PNG error = Load_SBit_Png( face->root.glyph, 0, 0, 32, metrics, stream->memory, stream->cursor, glyph_end - glyph_start - 8, TRUE ); #else error = FT_THROW( Unimplemented_Feature ); #endif break; case FT_MAKE_TAG( 'j', 'p', 'g', ' ' ): case FT_MAKE_TAG( 't', 'i', 'f', 'f' ): case FT_MAKE_TAG( 'r', 'g', 'b', 'l' ): /* used on iOS 7.1 */ error = FT_THROW( Unknown_File_Format ); break; default: error = FT_THROW( Unimplemented_Feature ); break; } FT_FRAME_EXIT(); if ( !error ) { FT_Short abearing; FT_UShort aadvance; tt_face_get_metrics( face, FALSE, glyph_index, &abearing, &aadvance ); metrics->horiBearingX = (FT_Short)originOffsetX; metrics->horiBearingY = (FT_Short)( -originOffsetY + metrics->height ); metrics->horiAdvance = (FT_Short)( aadvance * face->root.size->metrics.x_ppem / face->header.Units_Per_EM ); } return error; }
DoS Overflow
0
tt_face_load_sbix_image( TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics ) { FT_UInt sbix_pos, strike_offset, glyph_start, glyph_end; FT_ULong table_size; FT_Int originOffsetX, originOffsetY; FT_Tag graphicType; FT_Int recurse_depth = 0; FT_Error error; FT_Byte* p; FT_UNUSED( map ); metrics->width = 0; metrics->height = 0; p = face->sbit_table + 8 + 4 * strike_index; strike_offset = FT_NEXT_ULONG( p ); error = face->goto_table( face, TTAG_sbix, stream, &table_size ); if ( error ) return error; sbix_pos = FT_STREAM_POS(); retry: if ( glyph_index > (FT_UInt)face->root.num_glyphs ) return FT_THROW( Invalid_Argument ); if ( strike_offset >= table_size || table_size - strike_offset < 4 + glyph_index * 4 + 8 ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( sbix_pos + strike_offset + 4 + glyph_index * 4 ) || FT_FRAME_ENTER( 8 ) ) return error; glyph_start = FT_GET_ULONG(); glyph_end = FT_GET_ULONG(); FT_FRAME_EXIT(); if ( glyph_start == glyph_end ) return FT_THROW( Invalid_Argument ); if ( glyph_start > glyph_end || glyph_end - glyph_start < 8 || table_size - strike_offset < glyph_end ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( sbix_pos + strike_offset + glyph_start ) || FT_FRAME_ENTER( glyph_end - glyph_start ) ) return error; originOffsetX = FT_GET_SHORT(); originOffsetY = FT_GET_SHORT(); graphicType = FT_GET_TAG4(); switch ( graphicType ) { case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ): if ( recurse_depth < 4 ) { glyph_index = FT_GET_USHORT(); FT_FRAME_EXIT(); recurse_depth++; goto retry; } error = FT_THROW( Invalid_File_Format ); break; case FT_MAKE_TAG( 'p', 'n', 'g', ' ' ): #ifdef FT_CONFIG_OPTION_USE_PNG error = Load_SBit_Png( face->root.glyph, 0, 0, 32, metrics, stream->memory, stream->cursor, glyph_end - glyph_start - 8, TRUE ); #else error = FT_THROW( Unimplemented_Feature ); #endif break; case FT_MAKE_TAG( 'j', 'p', 'g', ' ' ): case FT_MAKE_TAG( 't', 'i', 'f', 'f' ): case FT_MAKE_TAG( 'r', 'g', 'b', 'l' ): /* used on iOS 7.1 */ error = FT_THROW( Unknown_File_Format ); break; default: error = FT_THROW( Unimplemented_Feature ); break; } FT_FRAME_EXIT(); if ( !error ) { FT_Short abearing; FT_UShort aadvance; tt_face_get_metrics( face, FALSE, glyph_index, &abearing, &aadvance ); metrics->horiBearingX = (FT_Short)originOffsetX; metrics->horiBearingY = (FT_Short)( -originOffsetY + metrics->height ); metrics->horiAdvance = (FT_Short)( aadvance * face->root.size->metrics.x_ppem / face->header.Units_Per_EM ); } return error; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,552
tt_face_load_strike_metrics( TT_Face face, FT_ULong strike_index, FT_Size_Metrics* metrics ) { if ( strike_index >= (FT_ULong)face->sbit_num_strikes ) return FT_THROW( Invalid_Argument ); switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { FT_Byte* strike; strike = face->sbit_table + 8 + strike_index * 48; metrics->x_ppem = (FT_UShort)strike[44]; metrics->y_ppem = (FT_UShort)strike[45]; metrics->ascender = (FT_Char)strike[16] << 6; /* hori.ascender */ metrics->descender = (FT_Char)strike[17] << 6; /* hori.descender */ metrics->height = metrics->ascender - metrics->descender; /* Is this correct? */ metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */ strike[18] + /* max_width */ (FT_Char)strike[23] /* min_advance_SB */ ) << 6; return FT_Err_Ok; } case TT_SBIT_TABLE_TYPE_SBIX: { FT_Stream stream = face->root.stream; FT_UInt offset, upem; FT_UShort ppem, resolution; TT_HoriHeader *hori; FT_ULong table_size; FT_Error error; FT_Byte* p; p = face->sbit_table + 8 + 4 * strike_index; offset = FT_NEXT_ULONG( p ); error = face->goto_table( face, TTAG_sbix, stream, &table_size ); if ( error ) return error; if ( offset + 4 > table_size ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( FT_STREAM_POS() + offset ) || FT_FRAME_ENTER( 4 ) ) return error; ppem = FT_GET_USHORT(); resolution = FT_GET_USHORT(); FT_UNUSED( resolution ); /* What to do with this? */ FT_FRAME_EXIT(); upem = face->header.Units_Per_EM; hori = &face->horizontal; metrics->x_ppem = ppem; metrics->y_ppem = ppem; metrics->ascender = ppem * hori->Ascender * 64 / upem; metrics->descender = ppem * hori->Descender * 64 / upem; metrics->height = ppem * ( hori->Ascender - hori->Descender + hori->Line_Gap ) * 64 / upem; metrics->max_advance = ppem * hori->advance_Width_Max * 64 / upem; return error; } default: return FT_THROW( Unknown_File_Format ); } }
DoS Overflow
0
tt_face_load_strike_metrics( TT_Face face, FT_ULong strike_index, FT_Size_Metrics* metrics ) { if ( strike_index >= (FT_ULong)face->sbit_num_strikes ) return FT_THROW( Invalid_Argument ); switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { FT_Byte* strike; strike = face->sbit_table + 8 + strike_index * 48; metrics->x_ppem = (FT_UShort)strike[44]; metrics->y_ppem = (FT_UShort)strike[45]; metrics->ascender = (FT_Char)strike[16] << 6; /* hori.ascender */ metrics->descender = (FT_Char)strike[17] << 6; /* hori.descender */ metrics->height = metrics->ascender - metrics->descender; /* Is this correct? */ metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */ strike[18] + /* max_width */ (FT_Char)strike[23] /* min_advance_SB */ ) << 6; return FT_Err_Ok; } case TT_SBIT_TABLE_TYPE_SBIX: { FT_Stream stream = face->root.stream; FT_UInt offset, upem; FT_UShort ppem, resolution; TT_HoriHeader *hori; FT_ULong table_size; FT_Error error; FT_Byte* p; p = face->sbit_table + 8 + 4 * strike_index; offset = FT_NEXT_ULONG( p ); error = face->goto_table( face, TTAG_sbix, stream, &table_size ); if ( error ) return error; if ( offset + 4 > table_size ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( FT_STREAM_POS() + offset ) || FT_FRAME_ENTER( 4 ) ) return error; ppem = FT_GET_USHORT(); resolution = FT_GET_USHORT(); FT_UNUSED( resolution ); /* What to do with this? */ FT_FRAME_EXIT(); upem = face->header.Units_Per_EM; hori = &face->horizontal; metrics->x_ppem = ppem; metrics->y_ppem = ppem; metrics->ascender = ppem * hori->Ascender * 64 / upem; metrics->descender = ppem * hori->Descender * 64 / upem; metrics->height = ppem * ( hori->Ascender - hori->Descender + hori->Line_Gap ) * 64 / upem; metrics->max_advance = ppem * hori->advance_Width_Max * 64 / upem; return error; } default: return FT_THROW( Unknown_File_Format ); } }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,553
tt_face_set_sbit_strike( TT_Face face, FT_Size_Request req, FT_ULong* astrike_index ) { return FT_Match_Size( (FT_Face)face, req, 0, astrike_index ); }
DoS Overflow
0
tt_face_set_sbit_strike( TT_Face face, FT_Size_Request req, FT_ULong* astrike_index ) { return FT_Match_Size( (FT_Face)face, req, 0, astrike_index ); }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,554
tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder decoder ) { FT_Error error = FT_Err_Ok; FT_UInt width, height; FT_Bitmap* map = decoder->bitmap; FT_Long size; if ( !decoder->metrics_loaded ) { error = FT_THROW( Invalid_Argument ); goto Exit; } width = decoder->metrics->width; height = decoder->metrics->height; map->width = (int)width; map->rows = (int)height; switch ( decoder->bit_depth ) { case 1: map->pixel_mode = FT_PIXEL_MODE_MONO; map->pitch = ( map->width + 7 ) >> 3; map->num_grays = 2; break; case 2: map->pixel_mode = FT_PIXEL_MODE_GRAY2; map->pitch = ( map->width + 3 ) >> 2; map->num_grays = 4; break; case 4: map->pixel_mode = FT_PIXEL_MODE_GRAY4; map->pitch = ( map->width + 1 ) >> 1; map->num_grays = 16; break; case 8: map->pixel_mode = FT_PIXEL_MODE_GRAY; map->pitch = map->width; map->num_grays = 256; break; case 32: map->pixel_mode = FT_PIXEL_MODE_BGRA; map->pitch = map->width * 4; map->num_grays = 256; break; default: error = FT_THROW( Invalid_File_Format ); goto Exit; } size = map->rows * map->pitch; /* check that there is no empty image */ if ( size == 0 ) goto Exit; /* exit successfully! */ error = ft_glyphslot_alloc_bitmap( decoder->face->root.glyph, size ); if ( error ) goto Exit; decoder->bitmap_allocated = 1; Exit: return error; }
DoS Overflow
0
tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder decoder ) { FT_Error error = FT_Err_Ok; FT_UInt width, height; FT_Bitmap* map = decoder->bitmap; FT_Long size; if ( !decoder->metrics_loaded ) { error = FT_THROW( Invalid_Argument ); goto Exit; } width = decoder->metrics->width; height = decoder->metrics->height; map->width = (int)width; map->rows = (int)height; switch ( decoder->bit_depth ) { case 1: map->pixel_mode = FT_PIXEL_MODE_MONO; map->pitch = ( map->width + 7 ) >> 3; map->num_grays = 2; break; case 2: map->pixel_mode = FT_PIXEL_MODE_GRAY2; map->pitch = ( map->width + 3 ) >> 2; map->num_grays = 4; break; case 4: map->pixel_mode = FT_PIXEL_MODE_GRAY4; map->pitch = ( map->width + 1 ) >> 1; map->num_grays = 16; break; case 8: map->pixel_mode = FT_PIXEL_MODE_GRAY; map->pitch = map->width; map->num_grays = 256; break; case 32: map->pixel_mode = FT_PIXEL_MODE_BGRA; map->pitch = map->width * 4; map->num_grays = 256; break; default: error = FT_THROW( Invalid_File_Format ); goto Exit; } size = map->rows * map->pitch; /* check that there is no empty image */ if ( size == 0 ) goto Exit; /* exit successfully! */ error = ft_glyphslot_alloc_bitmap( decoder->face->root.glyph, size ); if ( error ) goto Exit; decoder->bitmap_allocated = 1; Exit: return error; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,555
tt_sbit_decoder_done( TT_SBitDecoder decoder ) { FT_UNUSED( decoder ); }
DoS Overflow
0
tt_sbit_decoder_done( TT_SBitDecoder decoder ) { FT_UNUSED( decoder ); }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,556
tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos ) { FT_Error error = FT_Err_Ok; FT_Byte* line; FT_Int bit_height, bit_width, pitch, width, height, line_bits, h, nbits; FT_Bitmap* bitmap; FT_UShort rval; /* check that we can write the glyph into the bitmap */ bitmap = decoder->bitmap; bit_width = bitmap->width; bit_height = bitmap->rows; pitch = bitmap->pitch; line = bitmap->buffer; width = decoder->metrics->width; height = decoder->metrics->height; line_bits = width * decoder->bit_depth; if ( x_pos < 0 || x_pos + width > bit_width || y_pos < 0 || y_pos + height > bit_height ) { FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned:" " invalid bitmap dimensions\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( p + ( ( line_bits * height + 7 ) >> 3 ) > limit ) { FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* now do the blit */ /* adjust `line' to point to the first byte of the bitmap */ line += y_pos * pitch + ( x_pos >> 3 ); x_pos &= 7; /* the higher byte of `rval' is used as a buffer */ rval = 0; nbits = 0; for ( h = height; h > 0; h--, line += pitch ) { FT_Byte* pwrite = line; FT_Int w = line_bits; /* handle initial byte (in target bitmap) specially if necessary */ if ( x_pos ) { w = ( line_bits < 8 - x_pos ) ? line_bits : 8 - x_pos; if ( h == height ) { rval = *p++; nbits = x_pos; } else if ( nbits < w ) { if ( p < limit ) rval |= *p++; nbits += 8 - w; } else { rval >>= 8; nbits -= w; } *pwrite++ |= ( ( rval >> nbits ) & 0xFF ) & ( ~( 0xFF << w ) << ( 8 - w - x_pos ) ); rval <<= 8; w = line_bits - w; } /* handle medial bytes */ for ( ; w >= 8; w -= 8 ) { rval |= *p++; *pwrite++ |= ( rval >> nbits ) & 0xFF; rval <<= 8; } /* handle final byte if necessary */ if ( w > 0 ) { if ( nbits < w ) { if ( p < limit ) rval |= *p++; *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); nbits += 8 - w; rval <<= 8; } else { *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); nbits -= w; } } } Exit: if ( !error ) FT_TRACE3(( "tt_sbit_decoder_load_bit_aligned: loaded\n" )); return error; }
DoS Overflow
0
tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos ) { FT_Error error = FT_Err_Ok; FT_Byte* line; FT_Int bit_height, bit_width, pitch, width, height, line_bits, h, nbits; FT_Bitmap* bitmap; FT_UShort rval; /* check that we can write the glyph into the bitmap */ bitmap = decoder->bitmap; bit_width = bitmap->width; bit_height = bitmap->rows; pitch = bitmap->pitch; line = bitmap->buffer; width = decoder->metrics->width; height = decoder->metrics->height; line_bits = width * decoder->bit_depth; if ( x_pos < 0 || x_pos + width > bit_width || y_pos < 0 || y_pos + height > bit_height ) { FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned:" " invalid bitmap dimensions\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( p + ( ( line_bits * height + 7 ) >> 3 ) > limit ) { FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* now do the blit */ /* adjust `line' to point to the first byte of the bitmap */ line += y_pos * pitch + ( x_pos >> 3 ); x_pos &= 7; /* the higher byte of `rval' is used as a buffer */ rval = 0; nbits = 0; for ( h = height; h > 0; h--, line += pitch ) { FT_Byte* pwrite = line; FT_Int w = line_bits; /* handle initial byte (in target bitmap) specially if necessary */ if ( x_pos ) { w = ( line_bits < 8 - x_pos ) ? line_bits : 8 - x_pos; if ( h == height ) { rval = *p++; nbits = x_pos; } else if ( nbits < w ) { if ( p < limit ) rval |= *p++; nbits += 8 - w; } else { rval >>= 8; nbits -= w; } *pwrite++ |= ( ( rval >> nbits ) & 0xFF ) & ( ~( 0xFF << w ) << ( 8 - w - x_pos ) ); rval <<= 8; w = line_bits - w; } /* handle medial bytes */ for ( ; w >= 8; w -= 8 ) { rval |= *p++; *pwrite++ |= ( rval >> nbits ) & 0xFF; rval <<= 8; } /* handle final byte if necessary */ if ( w > 0 ) { if ( nbits < w ) { if ( p < limit ) rval |= *p++; *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); nbits += 8 - w; rval <<= 8; } else { *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); nbits -= w; } } } Exit: if ( !error ) FT_TRACE3(( "tt_sbit_decoder_load_bit_aligned: loaded\n" )); return error; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,557
tt_sbit_decoder_load_compound( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos ) { FT_Error error = FT_Err_Ok; FT_UInt num_components, nn; FT_Char horiBearingX = (FT_Char)decoder->metrics->horiBearingX; FT_Char horiBearingY = (FT_Char)decoder->metrics->horiBearingY; FT_Byte horiAdvance = (FT_Byte)decoder->metrics->horiAdvance; FT_Char vertBearingX = (FT_Char)decoder->metrics->vertBearingX; FT_Char vertBearingY = (FT_Char)decoder->metrics->vertBearingY; FT_Byte vertAdvance = (FT_Byte)decoder->metrics->vertAdvance; if ( p + 2 > limit ) goto Fail; num_components = FT_NEXT_USHORT( p ); if ( p + 4 * num_components > limit ) { FT_TRACE1(( "tt_sbit_decoder_load_compound: broken table\n" )); goto Fail; } FT_TRACE3(( "tt_sbit_decoder_load_compound: loading %d components\n", num_components )); for ( nn = 0; nn < num_components; nn++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); FT_Byte dx = FT_NEXT_BYTE( p ); FT_Byte dy = FT_NEXT_BYTE( p ); /* NB: a recursive call */ error = tt_sbit_decoder_load_image( decoder, gindex, x_pos + dx, y_pos + dy ); if ( error ) break; } FT_TRACE3(( "tt_sbit_decoder_load_compound: done\n" )); decoder->metrics->horiBearingX = horiBearingX; decoder->metrics->horiBearingY = horiBearingY; decoder->metrics->horiAdvance = horiAdvance; decoder->metrics->vertBearingX = vertBearingX; decoder->metrics->vertBearingY = vertBearingY; decoder->metrics->vertAdvance = vertAdvance; decoder->metrics->width = (FT_Byte)decoder->bitmap->width; decoder->metrics->height = (FT_Byte)decoder->bitmap->rows; Exit: return error; Fail: error = FT_THROW( Invalid_File_Format ); goto Exit; }
DoS Overflow
0
tt_sbit_decoder_load_compound( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos ) { FT_Error error = FT_Err_Ok; FT_UInt num_components, nn; FT_Char horiBearingX = (FT_Char)decoder->metrics->horiBearingX; FT_Char horiBearingY = (FT_Char)decoder->metrics->horiBearingY; FT_Byte horiAdvance = (FT_Byte)decoder->metrics->horiAdvance; FT_Char vertBearingX = (FT_Char)decoder->metrics->vertBearingX; FT_Char vertBearingY = (FT_Char)decoder->metrics->vertBearingY; FT_Byte vertAdvance = (FT_Byte)decoder->metrics->vertAdvance; if ( p + 2 > limit ) goto Fail; num_components = FT_NEXT_USHORT( p ); if ( p + 4 * num_components > limit ) { FT_TRACE1(( "tt_sbit_decoder_load_compound: broken table\n" )); goto Fail; } FT_TRACE3(( "tt_sbit_decoder_load_compound: loading %d components\n", num_components )); for ( nn = 0; nn < num_components; nn++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); FT_Byte dx = FT_NEXT_BYTE( p ); FT_Byte dy = FT_NEXT_BYTE( p ); /* NB: a recursive call */ error = tt_sbit_decoder_load_image( decoder, gindex, x_pos + dx, y_pos + dy ); if ( error ) break; } FT_TRACE3(( "tt_sbit_decoder_load_compound: done\n" )); decoder->metrics->horiBearingX = horiBearingX; decoder->metrics->horiBearingY = horiBearingY; decoder->metrics->horiAdvance = horiAdvance; decoder->metrics->vertBearingX = vertBearingX; decoder->metrics->vertBearingY = vertBearingY; decoder->metrics->vertAdvance = vertAdvance; decoder->metrics->width = (FT_Byte)decoder->bitmap->width; decoder->metrics->height = (FT_Byte)decoder->bitmap->rows; Exit: return error; Fail: error = FT_THROW( Invalid_File_Format ); goto Exit; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,558
tt_sbit_decoder_load_image( TT_SBitDecoder decoder, FT_UInt glyph_index, FT_Int x_pos, FT_Int y_pos ) { /* * First, we find the correct strike range that applies to this * glyph index. */ FT_Byte* p = decoder->eblc_base + decoder->strike_index_array; FT_Byte* p_limit = decoder->eblc_limit; FT_ULong num_ranges = decoder->strike_index_count; FT_UInt start, end, index_format, image_format; FT_ULong image_start = 0, image_end = 0, image_offset; for ( ; num_ranges > 0; num_ranges-- ) { start = FT_NEXT_USHORT( p ); end = FT_NEXT_USHORT( p ); if ( glyph_index >= start && glyph_index <= end ) goto FoundRange; p += 4; /* ignore index offset */ } goto NoBitmap; FoundRange: image_offset = FT_NEXT_ULONG( p ); /* overflow check */ p = decoder->eblc_base + decoder->strike_index_array; if ( image_offset > (FT_ULong)( p_limit - p ) ) goto Failure; p += image_offset; if ( p + 8 > p_limit ) goto NoBitmap; /* now find the glyph's location and extend within the ebdt table */ index_format = FT_NEXT_USHORT( p ); image_format = FT_NEXT_USHORT( p ); image_offset = FT_NEXT_ULONG ( p ); switch ( index_format ) { case 1: /* 4-byte offsets relative to `image_offset' */ p += 4 * ( glyph_index - start ); if ( p + 8 > p_limit ) goto NoBitmap; image_start = FT_NEXT_ULONG( p ); image_end = FT_NEXT_ULONG( p ); if ( image_start == image_end ) /* missing glyph */ goto NoBitmap; break; case 2: /* big metrics, constant image size */ { FT_ULong image_size; if ( p + 12 > p_limit ) goto NoBitmap; image_size = FT_NEXT_ULONG( p ); if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) goto NoBitmap; image_start = image_size * ( glyph_index - start ); image_end = image_start + image_size; } break; case 3: /* 2-byte offsets relative to 'image_offset' */ p += 2 * ( glyph_index - start ); if ( p + 4 > p_limit ) goto NoBitmap; image_start = FT_NEXT_USHORT( p ); image_end = FT_NEXT_USHORT( p ); if ( image_start == image_end ) /* missing glyph */ goto NoBitmap; break; case 4: /* sparse glyph array with (glyph,offset) pairs */ { FT_ULong mm, num_glyphs; if ( p + 4 > p_limit ) goto NoBitmap; num_glyphs = FT_NEXT_ULONG( p ); /* overflow check for p + ( num_glyphs + 1 ) * 4 */ if ( num_glyphs > (FT_ULong)( ( ( p_limit - p ) >> 2 ) - 1 ) ) goto NoBitmap; for ( mm = 0; mm < num_glyphs; mm++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex == glyph_index ) { image_start = FT_NEXT_USHORT( p ); p += 2; image_end = FT_PEEK_USHORT( p ); break; } p += 2; } if ( mm >= num_glyphs ) goto NoBitmap; } break; case 5: /* constant metrics with sparse glyph codes */ case 19: { FT_ULong image_size, mm, num_glyphs; if ( p + 16 > p_limit ) goto NoBitmap; image_size = FT_NEXT_ULONG( p ); if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) goto NoBitmap; num_glyphs = FT_NEXT_ULONG( p ); /* overflow check for p + 2 * num_glyphs */ if ( num_glyphs > (FT_ULong)( ( p_limit - p ) >> 1 ) ) goto NoBitmap; for ( mm = 0; mm < num_glyphs; mm++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex == glyph_index ) break; } if ( mm >= num_glyphs ) goto NoBitmap; image_start = image_size * mm; image_end = image_start + image_size; } break; default: goto NoBitmap; } if ( image_start > image_end ) goto NoBitmap; image_end -= image_start; image_start = image_offset + image_start; FT_TRACE3(( "tt_sbit_decoder_load_image:" " found sbit (format %d) for glyph index %d\n", image_format, glyph_index )); return tt_sbit_decoder_load_bitmap( decoder, image_format, image_start, image_end, x_pos, y_pos ); Failure: return FT_THROW( Invalid_Table ); NoBitmap: FT_TRACE4(( "tt_sbit_decoder_load_image:" " no sbit found for glyph index %d\n", glyph_index )); return FT_THROW( Invalid_Argument ); }
DoS Overflow
0
tt_sbit_decoder_load_image( TT_SBitDecoder decoder, FT_UInt glyph_index, FT_Int x_pos, FT_Int y_pos ) { /* * First, we find the correct strike range that applies to this * glyph index. */ FT_Byte* p = decoder->eblc_base + decoder->strike_index_array; FT_Byte* p_limit = decoder->eblc_limit; FT_ULong num_ranges = decoder->strike_index_count; FT_UInt start, end, index_format, image_format; FT_ULong image_start = 0, image_end = 0, image_offset; for ( ; num_ranges > 0; num_ranges-- ) { start = FT_NEXT_USHORT( p ); end = FT_NEXT_USHORT( p ); if ( glyph_index >= start && glyph_index <= end ) goto FoundRange; p += 4; /* ignore index offset */ } goto NoBitmap; FoundRange: image_offset = FT_NEXT_ULONG( p ); /* overflow check */ p = decoder->eblc_base + decoder->strike_index_array; if ( image_offset > (FT_ULong)( p_limit - p ) ) goto Failure; p += image_offset; if ( p + 8 > p_limit ) goto NoBitmap; /* now find the glyph's location and extend within the ebdt table */ index_format = FT_NEXT_USHORT( p ); image_format = FT_NEXT_USHORT( p ); image_offset = FT_NEXT_ULONG ( p ); switch ( index_format ) { case 1: /* 4-byte offsets relative to `image_offset' */ p += 4 * ( glyph_index - start ); if ( p + 8 > p_limit ) goto NoBitmap; image_start = FT_NEXT_ULONG( p ); image_end = FT_NEXT_ULONG( p ); if ( image_start == image_end ) /* missing glyph */ goto NoBitmap; break; case 2: /* big metrics, constant image size */ { FT_ULong image_size; if ( p + 12 > p_limit ) goto NoBitmap; image_size = FT_NEXT_ULONG( p ); if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) goto NoBitmap; image_start = image_size * ( glyph_index - start ); image_end = image_start + image_size; } break; case 3: /* 2-byte offsets relative to 'image_offset' */ p += 2 * ( glyph_index - start ); if ( p + 4 > p_limit ) goto NoBitmap; image_start = FT_NEXT_USHORT( p ); image_end = FT_NEXT_USHORT( p ); if ( image_start == image_end ) /* missing glyph */ goto NoBitmap; break; case 4: /* sparse glyph array with (glyph,offset) pairs */ { FT_ULong mm, num_glyphs; if ( p + 4 > p_limit ) goto NoBitmap; num_glyphs = FT_NEXT_ULONG( p ); /* overflow check for p + ( num_glyphs + 1 ) * 4 */ if ( num_glyphs > (FT_ULong)( ( ( p_limit - p ) >> 2 ) - 1 ) ) goto NoBitmap; for ( mm = 0; mm < num_glyphs; mm++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex == glyph_index ) { image_start = FT_NEXT_USHORT( p ); p += 2; image_end = FT_PEEK_USHORT( p ); break; } p += 2; } if ( mm >= num_glyphs ) goto NoBitmap; } break; case 5: /* constant metrics with sparse glyph codes */ case 19: { FT_ULong image_size, mm, num_glyphs; if ( p + 16 > p_limit ) goto NoBitmap; image_size = FT_NEXT_ULONG( p ); if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) goto NoBitmap; num_glyphs = FT_NEXT_ULONG( p ); /* overflow check for p + 2 * num_glyphs */ if ( num_glyphs > (FT_ULong)( ( p_limit - p ) >> 1 ) ) goto NoBitmap; for ( mm = 0; mm < num_glyphs; mm++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex == glyph_index ) break; } if ( mm >= num_glyphs ) goto NoBitmap; image_start = image_size * mm; image_end = image_start + image_size; } break; default: goto NoBitmap; } if ( image_start > image_end ) goto NoBitmap; image_end -= image_start; image_start = image_offset + image_start; FT_TRACE3(( "tt_sbit_decoder_load_image:" " found sbit (format %d) for glyph index %d\n", image_format, glyph_index )); return tt_sbit_decoder_load_bitmap( decoder, image_format, image_start, image_end, x_pos, y_pos ); Failure: return FT_THROW( Invalid_Table ); NoBitmap: FT_TRACE4(( "tt_sbit_decoder_load_image:" " no sbit found for glyph index %d\n", glyph_index )); return FT_THROW( Invalid_Argument ); }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,559
tt_sbit_decoder_load_metrics( TT_SBitDecoder decoder, FT_Byte* *pp, FT_Byte* limit, FT_Bool big ) { FT_Byte* p = *pp; TT_SBit_Metrics metrics = decoder->metrics; if ( p + 5 > limit ) goto Fail; metrics->height = p[0]; metrics->width = p[1]; metrics->horiBearingX = (FT_Char)p[2]; metrics->horiBearingY = (FT_Char)p[3]; metrics->horiAdvance = p[4]; p += 5; if ( big ) { if ( p + 3 > limit ) goto Fail; metrics->vertBearingX = (FT_Char)p[0]; metrics->vertBearingY = (FT_Char)p[1]; metrics->vertAdvance = p[2]; p += 3; } else { /* avoid uninitialized data in case there is no vertical info -- */ metrics->vertBearingX = 0; metrics->vertBearingY = 0; metrics->vertAdvance = 0; } decoder->metrics_loaded = 1; *pp = p; return FT_Err_Ok; Fail: FT_TRACE1(( "tt_sbit_decoder_load_metrics: broken table\n" )); return FT_THROW( Invalid_Argument ); }
DoS Overflow
0
tt_sbit_decoder_load_metrics( TT_SBitDecoder decoder, FT_Byte* *pp, FT_Byte* limit, FT_Bool big ) { FT_Byte* p = *pp; TT_SBit_Metrics metrics = decoder->metrics; if ( p + 5 > limit ) goto Fail; metrics->height = p[0]; metrics->width = p[1]; metrics->horiBearingX = (FT_Char)p[2]; metrics->horiBearingY = (FT_Char)p[3]; metrics->horiAdvance = p[4]; p += 5; if ( big ) { if ( p + 3 > limit ) goto Fail; metrics->vertBearingX = (FT_Char)p[0]; metrics->vertBearingY = (FT_Char)p[1]; metrics->vertAdvance = p[2]; p += 3; } else { /* avoid uninitialized data in case there is no vertical info -- */ metrics->vertBearingX = 0; metrics->vertBearingY = 0; metrics->vertAdvance = 0; } decoder->metrics_loaded = 1; *pp = p; return FT_Err_Ok; Fail: FT_TRACE1(( "tt_sbit_decoder_load_metrics: broken table\n" )); return FT_THROW( Invalid_Argument ); }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,560
tt_sbit_decoder_load_png( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos ) { FT_Error error = FT_Err_Ok; FT_ULong png_len; if ( limit - p < 4 ) { FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } png_len = FT_NEXT_ULONG( p ); if ( (FT_ULong)( limit - p ) < png_len ) { FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } error = Load_SBit_Png( decoder->face->root.glyph, x_pos, y_pos, decoder->bit_depth, decoder->metrics, decoder->stream->memory, p, png_len, FALSE ); Exit: if ( !error ) FT_TRACE3(( "tt_sbit_decoder_load_png: loaded\n" )); return error; }
DoS Overflow
0
tt_sbit_decoder_load_png( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos ) { FT_Error error = FT_Err_Ok; FT_ULong png_len; if ( limit - p < 4 ) { FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } png_len = FT_NEXT_ULONG( p ); if ( (FT_ULong)( limit - p ) < png_len ) { FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } error = Load_SBit_Png( decoder->face->root.glyph, x_pos, y_pos, decoder->bit_depth, decoder->metrics, decoder->stream->memory, p, png_len, FALSE ); Exit: if ( !error ) FT_TRACE3(( "tt_sbit_decoder_load_png: loaded\n" )); return error; }
@@ -394,9 +394,11 @@ p += 34; decoder->bit_depth = *p; - if ( decoder->strike_index_array > face->sbit_table_size || - decoder->strike_index_array + 8 * decoder->strike_index_count > - face->sbit_table_size ) + /* decoder->strike_index_array + */ + /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ + if ( decoder->strike_index_array > face->sbit_table_size || + decoder->strike_index_count > + ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); }
CWE-189
null
null
5,561
FT_Bitmap_Done( FT_Library library, FT_Bitmap *bitmap ) { FT_Memory memory; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !bitmap ) return FT_THROW( Invalid_Argument ); memory = library->memory; FT_FREE( bitmap->buffer ); *bitmap = null_bitmap; return FT_Err_Ok; }
DoS Overflow
0
FT_Bitmap_Done( FT_Library library, FT_Bitmap *bitmap ) { FT_Memory memory; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !bitmap ) return FT_THROW( Invalid_Argument ); memory = library->memory; FT_FREE( bitmap->buffer ); *bitmap = null_bitmap; return FT_Err_Ok; }
@@ -62,7 +62,7 @@ if ( pitch < 0 ) pitch = -pitch; - size = (FT_ULong)( pitch * source->rows ); + size = (FT_ULong)pitch * source->rows; if ( target->buffer ) { @@ -72,7 +72,7 @@ if ( target_pitch < 0 ) target_pitch = -target_pitch; - target_size = (FT_ULong)( target_pitch * target->rows ); + target_size = (FT_ULong)target_pitch * target->rows; if ( target_size != size ) (void)FT_QREALLOC( target->buffer, target_size, size ); @@ -109,7 +109,7 @@ int pitch; int new_pitch; FT_UInt bpp; - FT_Int i, width, height; + FT_UInt i, width, height; unsigned char* buffer = NULL; @@ -147,17 +147,17 @@ if ( ypixels == 0 && new_pitch <= pitch ) { /* zero the padding */ - FT_Int bit_width = pitch * 8; - FT_Int bit_last = ( width + xpixels ) * bpp; + FT_UInt bit_width = pitch * 8; + FT_UInt bit_last = ( width + xpixels ) * bpp; if ( bit_last < bit_width ) { FT_Byte* line = bitmap->buffer + ( bit_last >> 3 ); FT_Byte* end = bitmap->buffer + pitch; - FT_Int shift = bit_last & 7; + FT_UInt shift = bit_last & 7; FT_UInt mask = 0xFF00U >> shift; - FT_Int count = height; + FT_UInt count = height; for ( ; count > 0; count--, line += pitch, end += pitch ) @@ -186,7 +186,7 @@ /* thus take care of the flow direction */ if ( bitmap->pitch > 0 ) { - FT_Int len = ( width * bpp + 7 ) >> 3; + FT_UInt len = ( width * bpp + 7 ) >> 3; for ( i = 0; i < bitmap->rows; i++ ) @@ -195,7 +195,7 @@ } else { - FT_Int len = ( width * bpp + 7 ) >> 3; + FT_UInt len = ( width * bpp + 7 ) >> 3; for ( i = 0; i < bitmap->rows; i++ ) @@ -226,7 +226,8 @@ { FT_Error error; unsigned char* p; - FT_Int i, x, y, pitch; + FT_Int i, x, pitch; + FT_UInt y; FT_Int xstr, ystr; @@ -451,8 +452,8 @@ case FT_PIXEL_MODE_LCD_V: case FT_PIXEL_MODE_BGRA: { - FT_Int pad, old_target_pitch; - FT_Long old_size; + FT_Int pad, old_target_pitch; + FT_ULong old_size; old_target_pitch = target->pitch;
CWE-119
null
null
5,562
FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot ) { if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP && !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) ) { FT_Bitmap bitmap; FT_Error error; FT_Bitmap_New( &bitmap ); error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap ); if ( error ) return error; slot->bitmap = bitmap; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; } return FT_Err_Ok; }
DoS Overflow
0
FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot ) { if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP && !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) ) { FT_Bitmap bitmap; FT_Error error; FT_Bitmap_New( &bitmap ); error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap ); if ( error ) return error; slot->bitmap = bitmap; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; } return FT_Err_Ok; }
@@ -62,7 +62,7 @@ if ( pitch < 0 ) pitch = -pitch; - size = (FT_ULong)( pitch * source->rows ); + size = (FT_ULong)pitch * source->rows; if ( target->buffer ) { @@ -72,7 +72,7 @@ if ( target_pitch < 0 ) target_pitch = -target_pitch; - target_size = (FT_ULong)( target_pitch * target->rows ); + target_size = (FT_ULong)target_pitch * target->rows; if ( target_size != size ) (void)FT_QREALLOC( target->buffer, target_size, size ); @@ -109,7 +109,7 @@ int pitch; int new_pitch; FT_UInt bpp; - FT_Int i, width, height; + FT_UInt i, width, height; unsigned char* buffer = NULL; @@ -147,17 +147,17 @@ if ( ypixels == 0 && new_pitch <= pitch ) { /* zero the padding */ - FT_Int bit_width = pitch * 8; - FT_Int bit_last = ( width + xpixels ) * bpp; + FT_UInt bit_width = pitch * 8; + FT_UInt bit_last = ( width + xpixels ) * bpp; if ( bit_last < bit_width ) { FT_Byte* line = bitmap->buffer + ( bit_last >> 3 ); FT_Byte* end = bitmap->buffer + pitch; - FT_Int shift = bit_last & 7; + FT_UInt shift = bit_last & 7; FT_UInt mask = 0xFF00U >> shift; - FT_Int count = height; + FT_UInt count = height; for ( ; count > 0; count--, line += pitch, end += pitch ) @@ -186,7 +186,7 @@ /* thus take care of the flow direction */ if ( bitmap->pitch > 0 ) { - FT_Int len = ( width * bpp + 7 ) >> 3; + FT_UInt len = ( width * bpp + 7 ) >> 3; for ( i = 0; i < bitmap->rows; i++ ) @@ -195,7 +195,7 @@ } else { - FT_Int len = ( width * bpp + 7 ) >> 3; + FT_UInt len = ( width * bpp + 7 ) >> 3; for ( i = 0; i < bitmap->rows; i++ ) @@ -226,7 +226,8 @@ { FT_Error error; unsigned char* p; - FT_Int i, x, y, pitch; + FT_Int i, x, pitch; + FT_UInt y; FT_Int xstr, ystr; @@ -451,8 +452,8 @@ case FT_PIXEL_MODE_LCD_V: case FT_PIXEL_MODE_BGRA: { - FT_Int pad, old_target_pitch; - FT_Long old_size; + FT_Int pad, old_target_pitch; + FT_ULong old_size; old_target_pitch = target->pitch;
CWE-119
null
null
5,563
FTC_SNode_Compare( FTC_SNode snode, FTC_GQuery gquery, FTC_Cache cache, FT_Bool* list_changed ) { return ftc_snode_compare( FTC_NODE( snode ), gquery, cache, list_changed ); }
DoS Overflow
0
FTC_SNode_Compare( FTC_SNode snode, FTC_GQuery gquery, FTC_Cache cache, FT_Bool* list_changed ) { return ftc_snode_compare( FTC_NODE( snode ), gquery, cache, list_changed ); }
@@ -4,7 +4,7 @@ /* */ /* FreeType sbits manager (body). */ /* */ -/* Copyright 2000-2006, 2009-2011, 2013 by */ +/* Copyright 2000-2006, 2009-2011, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -142,12 +142,12 @@ goto BadGlyph; } - /* Check that our values fit into 8-bit containers! */ + /* Check whether our values fit into 8-bit containers! */ /* If this is not the case, our bitmap is too large */ /* and we will leave it as `missing' with sbit.buffer = 0 */ -#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d ) -#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d ) +#define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d ) +#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d ) /* horizontal advance in pixels */ xadvance = ( slot->advance.x + 32 ) >> 6;
CWE-119
null
null
5,564
FTC_SNode_New( FTC_SNode *psnode, FTC_GQuery gquery, FTC_Cache cache ) { FT_Memory memory = cache->memory; FT_Error error; FTC_SNode snode = NULL; FT_UInt gindex = gquery->gindex; FTC_Family family = gquery->family; FTC_SFamilyClass clazz = FTC_CACHE__SFAMILY_CLASS( cache ); FT_UInt total; FT_UInt node_count; total = clazz->family_get_count( family, cache->manager ); if ( total == 0 || gindex >= total ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !FT_NEW( snode ) ) { FT_UInt count, start; start = gindex - ( gindex % FTC_SBIT_ITEMS_PER_NODE ); count = total - start; if ( count > FTC_SBIT_ITEMS_PER_NODE ) count = FTC_SBIT_ITEMS_PER_NODE; FTC_GNode_Init( FTC_GNODE( snode ), start, family ); snode->count = count; for ( node_count = 0; node_count < count; node_count++ ) { snode->sbits[node_count].width = 255; } error = ftc_snode_load( snode, cache->manager, gindex, NULL ); if ( error ) { FTC_SNode_Free( snode, cache ); snode = NULL; } } Exit: *psnode = snode; return error; }
DoS Overflow
0
FTC_SNode_New( FTC_SNode *psnode, FTC_GQuery gquery, FTC_Cache cache ) { FT_Memory memory = cache->memory; FT_Error error; FTC_SNode snode = NULL; FT_UInt gindex = gquery->gindex; FTC_Family family = gquery->family; FTC_SFamilyClass clazz = FTC_CACHE__SFAMILY_CLASS( cache ); FT_UInt total; FT_UInt node_count; total = clazz->family_get_count( family, cache->manager ); if ( total == 0 || gindex >= total ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !FT_NEW( snode ) ) { FT_UInt count, start; start = gindex - ( gindex % FTC_SBIT_ITEMS_PER_NODE ); count = total - start; if ( count > FTC_SBIT_ITEMS_PER_NODE ) count = FTC_SBIT_ITEMS_PER_NODE; FTC_GNode_Init( FTC_GNODE( snode ), start, family ); snode->count = count; for ( node_count = 0; node_count < count; node_count++ ) { snode->sbits[node_count].width = 255; } error = ftc_snode_load( snode, cache->manager, gindex, NULL ); if ( error ) { FTC_SNode_Free( snode, cache ); snode = NULL; } } Exit: *psnode = snode; return error; }
@@ -4,7 +4,7 @@ /* */ /* FreeType sbits manager (body). */ /* */ -/* Copyright 2000-2006, 2009-2011, 2013 by */ +/* Copyright 2000-2006, 2009-2011, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -142,12 +142,12 @@ goto BadGlyph; } - /* Check that our values fit into 8-bit containers! */ + /* Check whether our values fit into 8-bit containers! */ /* If this is not the case, our bitmap is too large */ /* and we will leave it as `missing' with sbit.buffer = 0 */ -#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d ) -#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d ) +#define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d ) +#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d ) /* horizontal advance in pixels */ xadvance = ( slot->advance.x + 32 ) >> 6;
CWE-119
null
null
5,565
ftc_snode_compare( FTC_Node ftcsnode, FT_Pointer ftcgquery, FTC_Cache cache, FT_Bool* list_changed ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; FTC_GNode gnode = FTC_GNODE( snode ); FT_UInt gindex = gquery->gindex; FT_Bool result; if (list_changed) *list_changed = FALSE; result = FT_BOOL( gnode->family == gquery->family && (FT_UInt)( gindex - gnode->gindex ) < snode->count ); if ( result ) { /* check if we need to load the glyph bitmap now */ FTC_SBit sbit = snode->sbits + ( gindex - gnode->gindex ); /* * The following code illustrates what to do when you want to * perform operations that may fail within a lookup function. * * Here, we want to load a small bitmap on-demand; we thus * need to call the `ftc_snode_load' function which may return * a non-zero error code only when we are out of memory (OOM). * * The correct thing to do is to use @FTC_CACHE_TRYLOOP and * @FTC_CACHE_TRYLOOP_END in order to implement a retry loop * that is capable of flushing the cache incrementally when * an OOM errors occur. * * However, we need to `lock' the node before this operation to * prevent it from being flushed within the loop. * * When we exit the loop, we unlock the node, then check the `error' * variable. If it is non-zero, this means that the cache was * completely flushed and that no usable memory was found to load * the bitmap. * * We then prefer to return a value of 0 (i.e., NO MATCH). This * ensures that the caller will try to allocate a new node. * This operation consequently _fail_ and the lookup function * returns the appropriate OOM error code. * * Note that `buffer == NULL && width == 255' is a hack used to * tag `unavailable' bitmaps in the array. We should never try * to load these. * */ if ( sbit->buffer == NULL && sbit->width == 255 ) { FT_ULong size; FT_Error error; ftcsnode->ref_count++; /* lock node to prevent flushing */ /* in retry loop */ FTC_CACHE_TRYLOOP( cache ) { error = ftc_snode_load( snode, cache->manager, gindex, &size ); } FTC_CACHE_TRYLOOP_END( list_changed ); ftcsnode->ref_count--; /* unlock the node */ if ( error ) result = 0; else cache->manager->cur_weight += size; } } return result; }
DoS Overflow
0
ftc_snode_compare( FTC_Node ftcsnode, FT_Pointer ftcgquery, FTC_Cache cache, FT_Bool* list_changed ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; FTC_GNode gnode = FTC_GNODE( snode ); FT_UInt gindex = gquery->gindex; FT_Bool result; if (list_changed) *list_changed = FALSE; result = FT_BOOL( gnode->family == gquery->family && (FT_UInt)( gindex - gnode->gindex ) < snode->count ); if ( result ) { /* check if we need to load the glyph bitmap now */ FTC_SBit sbit = snode->sbits + ( gindex - gnode->gindex ); /* * The following code illustrates what to do when you want to * perform operations that may fail within a lookup function. * * Here, we want to load a small bitmap on-demand; we thus * need to call the `ftc_snode_load' function which may return * a non-zero error code only when we are out of memory (OOM). * * The correct thing to do is to use @FTC_CACHE_TRYLOOP and * @FTC_CACHE_TRYLOOP_END in order to implement a retry loop * that is capable of flushing the cache incrementally when * an OOM errors occur. * * However, we need to `lock' the node before this operation to * prevent it from being flushed within the loop. * * When we exit the loop, we unlock the node, then check the `error' * variable. If it is non-zero, this means that the cache was * completely flushed and that no usable memory was found to load * the bitmap. * * We then prefer to return a value of 0 (i.e., NO MATCH). This * ensures that the caller will try to allocate a new node. * This operation consequently _fail_ and the lookup function * returns the appropriate OOM error code. * * Note that `buffer == NULL && width == 255' is a hack used to * tag `unavailable' bitmaps in the array. We should never try * to load these. * */ if ( sbit->buffer == NULL && sbit->width == 255 ) { FT_ULong size; FT_Error error; ftcsnode->ref_count++; /* lock node to prevent flushing */ /* in retry loop */ FTC_CACHE_TRYLOOP( cache ) { error = ftc_snode_load( snode, cache->manager, gindex, &size ); } FTC_CACHE_TRYLOOP_END( list_changed ); ftcsnode->ref_count--; /* unlock the node */ if ( error ) result = 0; else cache->manager->cur_weight += size; } } return result; }
@@ -4,7 +4,7 @@ /* */ /* FreeType sbits manager (body). */ /* */ -/* Copyright 2000-2006, 2009-2011, 2013 by */ +/* Copyright 2000-2006, 2009-2011, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -142,12 +142,12 @@ goto BadGlyph; } - /* Check that our values fit into 8-bit containers! */ + /* Check whether our values fit into 8-bit containers! */ /* If this is not the case, our bitmap is too large */ /* and we will leave it as `missing' with sbit.buffer = 0 */ -#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d ) -#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d ) +#define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d ) +#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d ) /* horizontal advance in pixels */ xadvance = ( slot->advance.x + 32 ) >> 6;
CWE-119
null
null
5,566
ftc_snode_free( FTC_Node ftcsnode, FTC_Cache cache ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FTC_SBit sbit = snode->sbits; FT_UInt count = snode->count; FT_Memory memory = cache->memory; for ( ; count > 0; sbit++, count-- ) FT_FREE( sbit->buffer ); FTC_GNode_Done( FTC_GNODE( snode ), cache ); FT_FREE( snode ); }
DoS Overflow
0
ftc_snode_free( FTC_Node ftcsnode, FTC_Cache cache ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FTC_SBit sbit = snode->sbits; FT_UInt count = snode->count; FT_Memory memory = cache->memory; for ( ; count > 0; sbit++, count-- ) FT_FREE( sbit->buffer ); FTC_GNode_Done( FTC_GNODE( snode ), cache ); FT_FREE( snode ); }
@@ -4,7 +4,7 @@ /* */ /* FreeType sbits manager (body). */ /* */ -/* Copyright 2000-2006, 2009-2011, 2013 by */ +/* Copyright 2000-2006, 2009-2011, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -142,12 +142,12 @@ goto BadGlyph; } - /* Check that our values fit into 8-bit containers! */ + /* Check whether our values fit into 8-bit containers! */ /* If this is not the case, our bitmap is too large */ /* and we will leave it as `missing' with sbit.buffer = 0 */ -#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d ) -#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d ) +#define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d ) +#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d ) /* horizontal advance in pixels */ xadvance = ( slot->advance.x + 32 ) >> 6;
CWE-119
null
null
5,567
ftc_snode_new( FTC_Node *ftcpsnode, FT_Pointer ftcgquery, FTC_Cache cache ) { FTC_SNode *psnode = (FTC_SNode*)ftcpsnode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; return FTC_SNode_New( psnode, gquery, cache ); }
DoS Overflow
0
ftc_snode_new( FTC_Node *ftcpsnode, FT_Pointer ftcgquery, FTC_Cache cache ) { FTC_SNode *psnode = (FTC_SNode*)ftcpsnode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; return FTC_SNode_New( psnode, gquery, cache ); }
@@ -4,7 +4,7 @@ /* */ /* FreeType sbits manager (body). */ /* */ -/* Copyright 2000-2006, 2009-2011, 2013 by */ +/* Copyright 2000-2006, 2009-2011, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -142,12 +142,12 @@ goto BadGlyph; } - /* Check that our values fit into 8-bit containers! */ + /* Check whether our values fit into 8-bit containers! */ /* If this is not the case, our bitmap is too large */ /* and we will leave it as `missing' with sbit.buffer = 0 */ -#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d ) -#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d ) +#define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d ) +#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d ) /* horizontal advance in pixels */ xadvance = ( slot->advance.x + 32 ) >> 6;
CWE-119
null
null
5,568
ftc_snode_weight( FTC_Node ftcsnode, FTC_Cache cache ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FT_UInt count = snode->count; FTC_SBit sbit = snode->sbits; FT_Int pitch; FT_Offset size; FT_UNUSED( cache ); FT_ASSERT( snode->count <= FTC_SBIT_ITEMS_PER_NODE ); /* the node itself */ size = sizeof ( *snode ); for ( ; count > 0; count--, sbit++ ) { if ( sbit->buffer ) { pitch = sbit->pitch; if ( pitch < 0 ) pitch = -pitch; /* add the size of a given glyph image */ size += pitch * sbit->height; } } return size; }
DoS Overflow
0
ftc_snode_weight( FTC_Node ftcsnode, FTC_Cache cache ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FT_UInt count = snode->count; FTC_SBit sbit = snode->sbits; FT_Int pitch; FT_Offset size; FT_UNUSED( cache ); FT_ASSERT( snode->count <= FTC_SBIT_ITEMS_PER_NODE ); /* the node itself */ size = sizeof ( *snode ); for ( ; count > 0; count--, sbit++ ) { if ( sbit->buffer ) { pitch = sbit->pitch; if ( pitch < 0 ) pitch = -pitch; /* add the size of a given glyph image */ size += pitch * sbit->height; } } return size; }
@@ -4,7 +4,7 @@ /* */ /* FreeType sbits manager (body). */ /* */ -/* Copyright 2000-2006, 2009-2011, 2013 by */ +/* Copyright 2000-2006, 2009-2011, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -142,12 +142,12 @@ goto BadGlyph; } - /* Check that our values fit into 8-bit containers! */ + /* Check whether our values fit into 8-bit containers! */ /* If this is not the case, our bitmap is too large */ /* and we will leave it as `missing' with sbit.buffer = 0 */ -#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d ) -#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d ) +#define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d ) +#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d ) /* horizontal advance in pixels */ xadvance = ( slot->advance.x + 32 ) >> 6;
CWE-119
null
null
5,569
Bezier_Down( RAS_ARGS Int degree, TSplitter splitter, Long miny, Long maxy ) { TPoint* arc = ras.arc; Bool result, fresh; arc[0].y = -arc[0].y; arc[1].y = -arc[1].y; arc[2].y = -arc[2].y; if ( degree > 2 ) arc[3].y = -arc[3].y; fresh = ras.fresh; result = Bezier_Up( RAS_VARS degree, splitter, -maxy, -miny ); if ( fresh && !ras.fresh ) ras.cProfile->start = -ras.cProfile->start; arc[0].y = -arc[0].y; return result; }
DoS Overflow
0
Bezier_Down( RAS_ARGS Int degree, TSplitter splitter, Long miny, Long maxy ) { TPoint* arc = ras.arc; Bool result, fresh; arc[0].y = -arc[0].y; arc[1].y = -arc[1].y; arc[2].y = -arc[2].y; if ( degree > 2 ) arc[3].y = -arc[3].y; fresh = ras.fresh; result = Bezier_Up( RAS_VARS degree, splitter, -maxy, -miny ); if ( fresh && !ras.fresh ) ras.cProfile->start = -ras.cProfile->start; arc[0].y = -arc[0].y; return result; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,570
Conic_To( RAS_ARGS Long cx, Long cy, Long x, Long y ) { Long y1, y2, y3, x3, ymin, ymax; TStates state_bez; ras.arc = ras.arcs; ras.arc[2].x = ras.lastX; ras.arc[2].y = ras.lastY; ras.arc[1].x = cx; ras.arc[1].y = cy; ras.arc[0].x = x; ras.arc[0].y = y; do { y1 = ras.arc[2].y; y2 = ras.arc[1].y; y3 = ras.arc[0].y; x3 = ras.arc[0].x; /* first, categorize the Bezier arc */ if ( y1 <= y3 ) { ymin = y1; ymax = y3; } else { ymin = y3; ymax = y1; } if ( y2 < ymin || y2 > ymax ) { /* this arc has no given direction, split it! */ Split_Conic( ras.arc ); ras.arc += 2; } else if ( y1 == y3 ) { /* this arc is flat, ignore it and pop it from the Bezier stack */ ras.arc -= 2; } else { /* the arc is y-monotonous, either ascending or descending */ /* detect a change of direction */ state_bez = y1 < y3 ? Ascending_State : Descending_State; if ( ras.state != state_bez ) { Bool o = state_bez == Ascending_State ? IS_BOTTOM_OVERSHOOT( y1 ) : IS_TOP_OVERSHOOT( y1 ); /* finalize current profile if any */ if ( ras.state != Unknown_State && End_Profile( RAS_VARS o ) ) goto Fail; /* create a new profile */ if ( New_Profile( RAS_VARS state_bez, o ) ) goto Fail; } /* now call the appropriate routine */ if ( state_bez == Ascending_State ) { if ( Bezier_Up( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) ) goto Fail; } else if ( Bezier_Down( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) ) goto Fail; } } while ( ras.arc >= ras.arcs ); ras.lastX = x3; ras.lastY = y3; return SUCCESS; Fail: return FAILURE; }
DoS Overflow
0
Conic_To( RAS_ARGS Long cx, Long cy, Long x, Long y ) { Long y1, y2, y3, x3, ymin, ymax; TStates state_bez; ras.arc = ras.arcs; ras.arc[2].x = ras.lastX; ras.arc[2].y = ras.lastY; ras.arc[1].x = cx; ras.arc[1].y = cy; ras.arc[0].x = x; ras.arc[0].y = y; do { y1 = ras.arc[2].y; y2 = ras.arc[1].y; y3 = ras.arc[0].y; x3 = ras.arc[0].x; /* first, categorize the Bezier arc */ if ( y1 <= y3 ) { ymin = y1; ymax = y3; } else { ymin = y3; ymax = y1; } if ( y2 < ymin || y2 > ymax ) { /* this arc has no given direction, split it! */ Split_Conic( ras.arc ); ras.arc += 2; } else if ( y1 == y3 ) { /* this arc is flat, ignore it and pop it from the Bezier stack */ ras.arc -= 2; } else { /* the arc is y-monotonous, either ascending or descending */ /* detect a change of direction */ state_bez = y1 < y3 ? Ascending_State : Descending_State; if ( ras.state != state_bez ) { Bool o = state_bez == Ascending_State ? IS_BOTTOM_OVERSHOOT( y1 ) : IS_TOP_OVERSHOOT( y1 ); /* finalize current profile if any */ if ( ras.state != Unknown_State && End_Profile( RAS_VARS o ) ) goto Fail; /* create a new profile */ if ( New_Profile( RAS_VARS state_bez, o ) ) goto Fail; } /* now call the appropriate routine */ if ( state_bez == Ascending_State ) { if ( Bezier_Up( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) ) goto Fail; } else if ( Bezier_Down( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) ) goto Fail; } } while ( ras.arc >= ras.arcs ); ras.lastX = x3; ras.lastY = y3; return SUCCESS; Fail: return FAILURE; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,571
Convert_Glyph( RAS_ARGS int flipped ) { int i; unsigned start; ras.fProfile = NULL; ras.joint = FALSE; ras.fresh = FALSE; ras.maxBuff = ras.sizeBuff - AlignProfileSize; ras.numTurns = 0; ras.cProfile = (PProfile)ras.top; ras.cProfile->offset = ras.top; ras.num_Profs = 0; start = 0; for ( i = 0; i < ras.outline.n_contours; i++ ) { PProfile lastProfile; Bool o; ras.state = Unknown_State; ras.gProfile = NULL; if ( Decompose_Curve( RAS_VARS (unsigned short)start, ras.outline.contours[i], flipped ) ) return FAILURE; start = ras.outline.contours[i] + 1; /* we must now check whether the extreme arcs join or not */ if ( FRAC( ras.lastY ) == 0 && ras.lastY >= ras.minY && ras.lastY <= ras.maxY ) if ( ras.gProfile && ( ras.gProfile->flags & Flow_Up ) == ( ras.cProfile->flags & Flow_Up ) ) ras.top--; /* Note that ras.gProfile can be nil if the contour was too small */ /* to be drawn. */ lastProfile = ras.cProfile; if ( ras.cProfile->flags & Flow_Up ) o = IS_TOP_OVERSHOOT( ras.lastY ); else o = IS_BOTTOM_OVERSHOOT( ras.lastY ); if ( End_Profile( RAS_VARS o ) ) return FAILURE; /* close the `next profile in contour' linked list */ if ( ras.gProfile ) lastProfile->next = ras.gProfile; } if ( Finalize_Profile_Table( RAS_VAR ) ) return FAILURE; return (Bool)( ras.top < ras.maxBuff ? SUCCESS : FAILURE ); }
DoS Overflow
0
Convert_Glyph( RAS_ARGS int flipped ) { int i; unsigned start; ras.fProfile = NULL; ras.joint = FALSE; ras.fresh = FALSE; ras.maxBuff = ras.sizeBuff - AlignProfileSize; ras.numTurns = 0; ras.cProfile = (PProfile)ras.top; ras.cProfile->offset = ras.top; ras.num_Profs = 0; start = 0; for ( i = 0; i < ras.outline.n_contours; i++ ) { PProfile lastProfile; Bool o; ras.state = Unknown_State; ras.gProfile = NULL; if ( Decompose_Curve( RAS_VARS (unsigned short)start, ras.outline.contours[i], flipped ) ) return FAILURE; start = ras.outline.contours[i] + 1; /* we must now check whether the extreme arcs join or not */ if ( FRAC( ras.lastY ) == 0 && ras.lastY >= ras.minY && ras.lastY <= ras.maxY ) if ( ras.gProfile && ( ras.gProfile->flags & Flow_Up ) == ( ras.cProfile->flags & Flow_Up ) ) ras.top--; /* Note that ras.gProfile can be nil if the contour was too small */ /* to be drawn. */ lastProfile = ras.cProfile; if ( ras.cProfile->flags & Flow_Up ) o = IS_TOP_OVERSHOOT( ras.lastY ); else o = IS_BOTTOM_OVERSHOOT( ras.lastY ); if ( End_Profile( RAS_VARS o ) ) return FAILURE; /* close the `next profile in contour' linked list */ if ( ras.gProfile ) lastProfile->next = ras.gProfile; } if ( Finalize_Profile_Table( RAS_VAR ) ) return FAILURE; return (Bool)( ras.top < ras.maxBuff ? SUCCESS : FAILURE ); }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,572
Cubic_To( RAS_ARGS Long cx1, Long cy1, Long cx2, Long cy2, Long x, Long y ) { Long y1, y2, y3, y4, x4, ymin1, ymax1, ymin2, ymax2; TStates state_bez; ras.arc = ras.arcs; ras.arc[3].x = ras.lastX; ras.arc[3].y = ras.lastY; ras.arc[2].x = cx1; ras.arc[2].y = cy1; ras.arc[1].x = cx2; ras.arc[1].y = cy2; ras.arc[0].x = x; ras.arc[0].y = y; do { y1 = ras.arc[3].y; y2 = ras.arc[2].y; y3 = ras.arc[1].y; y4 = ras.arc[0].y; x4 = ras.arc[0].x; /* first, categorize the Bezier arc */ if ( y1 <= y4 ) { ymin1 = y1; ymax1 = y4; } else { ymin1 = y4; ymax1 = y1; } if ( y2 <= y3 ) { ymin2 = y2; ymax2 = y3; } else { ymin2 = y3; ymax2 = y2; } if ( ymin2 < ymin1 || ymax2 > ymax1 ) { /* this arc has no given direction, split it! */ Split_Cubic( ras.arc ); ras.arc += 3; } else if ( y1 == y4 ) { /* this arc is flat, ignore it and pop it from the Bezier stack */ ras.arc -= 3; } else { state_bez = ( y1 <= y4 ) ? Ascending_State : Descending_State; /* detect a change of direction */ if ( ras.state != state_bez ) { Bool o = state_bez == Ascending_State ? IS_BOTTOM_OVERSHOOT( y1 ) : IS_TOP_OVERSHOOT( y1 ); /* finalize current profile if any */ if ( ras.state != Unknown_State && End_Profile( RAS_VARS o ) ) goto Fail; if ( New_Profile( RAS_VARS state_bez, o ) ) goto Fail; } /* compute intersections */ if ( state_bez == Ascending_State ) { if ( Bezier_Up( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) ) goto Fail; } else if ( Bezier_Down( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) ) goto Fail; } } while ( ras.arc >= ras.arcs ); ras.lastX = x4; ras.lastY = y4; return SUCCESS; Fail: return FAILURE; }
DoS Overflow
0
Cubic_To( RAS_ARGS Long cx1, Long cy1, Long cx2, Long cy2, Long x, Long y ) { Long y1, y2, y3, y4, x4, ymin1, ymax1, ymin2, ymax2; TStates state_bez; ras.arc = ras.arcs; ras.arc[3].x = ras.lastX; ras.arc[3].y = ras.lastY; ras.arc[2].x = cx1; ras.arc[2].y = cy1; ras.arc[1].x = cx2; ras.arc[1].y = cy2; ras.arc[0].x = x; ras.arc[0].y = y; do { y1 = ras.arc[3].y; y2 = ras.arc[2].y; y3 = ras.arc[1].y; y4 = ras.arc[0].y; x4 = ras.arc[0].x; /* first, categorize the Bezier arc */ if ( y1 <= y4 ) { ymin1 = y1; ymax1 = y4; } else { ymin1 = y4; ymax1 = y1; } if ( y2 <= y3 ) { ymin2 = y2; ymax2 = y3; } else { ymin2 = y3; ymax2 = y2; } if ( ymin2 < ymin1 || ymax2 > ymax1 ) { /* this arc has no given direction, split it! */ Split_Cubic( ras.arc ); ras.arc += 3; } else if ( y1 == y4 ) { /* this arc is flat, ignore it and pop it from the Bezier stack */ ras.arc -= 3; } else { state_bez = ( y1 <= y4 ) ? Ascending_State : Descending_State; /* detect a change of direction */ if ( ras.state != state_bez ) { Bool o = state_bez == Ascending_State ? IS_BOTTOM_OVERSHOOT( y1 ) : IS_TOP_OVERSHOOT( y1 ); /* finalize current profile if any */ if ( ras.state != Unknown_State && End_Profile( RAS_VARS o ) ) goto Fail; if ( New_Profile( RAS_VARS state_bez, o ) ) goto Fail; } /* compute intersections */ if ( state_bez == Ascending_State ) { if ( Bezier_Up( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) ) goto Fail; } else if ( Bezier_Down( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) ) goto Fail; } } while ( ras.arc >= ras.arcs ); ras.lastX = x4; ras.lastY = y4; return SUCCESS; Fail: return FAILURE; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,573
Decompose_Curve( RAS_ARGS UShort first, UShort last, int flipped ) { FT_Vector v_last; FT_Vector v_control; FT_Vector v_start; FT_Vector* points; FT_Vector* point; FT_Vector* limit; char* tags; unsigned tag; /* current point's state */ points = ras.outline.points; limit = points + last; v_start.x = SCALED( points[first].x ); v_start.y = SCALED( points[first].y ); v_last.x = SCALED( points[last].x ); v_last.y = SCALED( points[last].y ); if ( flipped ) { SWAP_( v_start.x, v_start.y ); SWAP_( v_last.x, v_last.y ); } v_control = v_start; point = points + first; tags = ras.outline.tags + first; /* set scan mode if necessary */ if ( tags[0] & FT_CURVE_TAG_HAS_SCANMODE ) ras.dropOutControl = (Byte)tags[0] >> 5; tag = FT_CURVE_TAG( tags[0] ); /* A contour cannot start with a cubic control point! */ if ( tag == FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; /* check first point to determine origin */ if ( tag == FT_CURVE_TAG_CONIC ) { /* first point is conic control. Yes, this happens. */ if ( FT_CURVE_TAG( ras.outline.tags[last] ) == FT_CURVE_TAG_ON ) { /* start at last point if it is on the curve */ v_start = v_last; limit--; } else { /* if both first and last points are conic, */ /* start at their middle and record its position */ /* for closure */ v_start.x = ( v_start.x + v_last.x ) / 2; v_start.y = ( v_start.y + v_last.y ) / 2; /* v_last = v_start; */ } point--; tags--; } ras.lastX = v_start.x; ras.lastY = v_start.y; while ( point < limit ) { point++; tags++; tag = FT_CURVE_TAG( tags[0] ); switch ( tag ) { case FT_CURVE_TAG_ON: /* emit a single line_to */ { Long x, y; x = SCALED( point->x ); y = SCALED( point->y ); if ( flipped ) SWAP_( x, y ); if ( Line_To( RAS_VARS x, y ) ) goto Fail; continue; } case FT_CURVE_TAG_CONIC: /* consume conic arcs */ v_control.x = SCALED( point[0].x ); v_control.y = SCALED( point[0].y ); if ( flipped ) SWAP_( v_control.x, v_control.y ); Do_Conic: if ( point < limit ) { FT_Vector v_middle; Long x, y; point++; tags++; tag = FT_CURVE_TAG( tags[0] ); x = SCALED( point[0].x ); y = SCALED( point[0].y ); if ( flipped ) SWAP_( x, y ); if ( tag == FT_CURVE_TAG_ON ) { if ( Conic_To( RAS_VARS v_control.x, v_control.y, x, y ) ) goto Fail; continue; } if ( tag != FT_CURVE_TAG_CONIC ) goto Invalid_Outline; v_middle.x = ( v_control.x + x ) / 2; v_middle.y = ( v_control.y + y ) / 2; if ( Conic_To( RAS_VARS v_control.x, v_control.y, v_middle.x, v_middle.y ) ) goto Fail; v_control.x = x; v_control.y = y; goto Do_Conic; } if ( Conic_To( RAS_VARS v_control.x, v_control.y, v_start.x, v_start.y ) ) goto Fail; goto Close; default: /* FT_CURVE_TAG_CUBIC */ { Long x1, y1, x2, y2, x3, y3; if ( point + 1 > limit || FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; point += 2; tags += 2; x1 = SCALED( point[-2].x ); y1 = SCALED( point[-2].y ); x2 = SCALED( point[-1].x ); y2 = SCALED( point[-1].y ); if ( flipped ) { SWAP_( x1, y1 ); SWAP_( x2, y2 ); } if ( point <= limit ) { x3 = SCALED( point[0].x ); y3 = SCALED( point[0].y ); if ( flipped ) SWAP_( x3, y3 ); if ( Cubic_To( RAS_VARS x1, y1, x2, y2, x3, y3 ) ) goto Fail; continue; } if ( Cubic_To( RAS_VARS x1, y1, x2, y2, v_start.x, v_start.y ) ) goto Fail; goto Close; } } } /* close the contour with a line segment */ if ( Line_To( RAS_VARS v_start.x, v_start.y ) ) goto Fail; Close: return SUCCESS; Invalid_Outline: ras.error = FT_THROW( Invalid ); Fail: return FAILURE; }
DoS Overflow
0
Decompose_Curve( RAS_ARGS UShort first, UShort last, int flipped ) { FT_Vector v_last; FT_Vector v_control; FT_Vector v_start; FT_Vector* points; FT_Vector* point; FT_Vector* limit; char* tags; unsigned tag; /* current point's state */ points = ras.outline.points; limit = points + last; v_start.x = SCALED( points[first].x ); v_start.y = SCALED( points[first].y ); v_last.x = SCALED( points[last].x ); v_last.y = SCALED( points[last].y ); if ( flipped ) { SWAP_( v_start.x, v_start.y ); SWAP_( v_last.x, v_last.y ); } v_control = v_start; point = points + first; tags = ras.outline.tags + first; /* set scan mode if necessary */ if ( tags[0] & FT_CURVE_TAG_HAS_SCANMODE ) ras.dropOutControl = (Byte)tags[0] >> 5; tag = FT_CURVE_TAG( tags[0] ); /* A contour cannot start with a cubic control point! */ if ( tag == FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; /* check first point to determine origin */ if ( tag == FT_CURVE_TAG_CONIC ) { /* first point is conic control. Yes, this happens. */ if ( FT_CURVE_TAG( ras.outline.tags[last] ) == FT_CURVE_TAG_ON ) { /* start at last point if it is on the curve */ v_start = v_last; limit--; } else { /* if both first and last points are conic, */ /* start at their middle and record its position */ /* for closure */ v_start.x = ( v_start.x + v_last.x ) / 2; v_start.y = ( v_start.y + v_last.y ) / 2; /* v_last = v_start; */ } point--; tags--; } ras.lastX = v_start.x; ras.lastY = v_start.y; while ( point < limit ) { point++; tags++; tag = FT_CURVE_TAG( tags[0] ); switch ( tag ) { case FT_CURVE_TAG_ON: /* emit a single line_to */ { Long x, y; x = SCALED( point->x ); y = SCALED( point->y ); if ( flipped ) SWAP_( x, y ); if ( Line_To( RAS_VARS x, y ) ) goto Fail; continue; } case FT_CURVE_TAG_CONIC: /* consume conic arcs */ v_control.x = SCALED( point[0].x ); v_control.y = SCALED( point[0].y ); if ( flipped ) SWAP_( v_control.x, v_control.y ); Do_Conic: if ( point < limit ) { FT_Vector v_middle; Long x, y; point++; tags++; tag = FT_CURVE_TAG( tags[0] ); x = SCALED( point[0].x ); y = SCALED( point[0].y ); if ( flipped ) SWAP_( x, y ); if ( tag == FT_CURVE_TAG_ON ) { if ( Conic_To( RAS_VARS v_control.x, v_control.y, x, y ) ) goto Fail; continue; } if ( tag != FT_CURVE_TAG_CONIC ) goto Invalid_Outline; v_middle.x = ( v_control.x + x ) / 2; v_middle.y = ( v_control.y + y ) / 2; if ( Conic_To( RAS_VARS v_control.x, v_control.y, v_middle.x, v_middle.y ) ) goto Fail; v_control.x = x; v_control.y = y; goto Do_Conic; } if ( Conic_To( RAS_VARS v_control.x, v_control.y, v_start.x, v_start.y ) ) goto Fail; goto Close; default: /* FT_CURVE_TAG_CUBIC */ { Long x1, y1, x2, y2, x3, y3; if ( point + 1 > limit || FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; point += 2; tags += 2; x1 = SCALED( point[-2].x ); y1 = SCALED( point[-2].y ); x2 = SCALED( point[-1].x ); y2 = SCALED( point[-1].y ); if ( flipped ) { SWAP_( x1, y1 ); SWAP_( x2, y2 ); } if ( point <= limit ) { x3 = SCALED( point[0].x ); y3 = SCALED( point[0].y ); if ( flipped ) SWAP_( x3, y3 ); if ( Cubic_To( RAS_VARS x1, y1, x2, y2, x3, y3 ) ) goto Fail; continue; } if ( Cubic_To( RAS_VARS x1, y1, x2, y2, v_start.x, v_start.y ) ) goto Fail; goto Close; } } } /* close the contour with a line segment */ if ( Line_To( RAS_VARS v_start.x, v_start.y ) ) goto Fail; Close: return SUCCESS; Invalid_Outline: ras.error = FT_THROW( Invalid ); Fail: return FAILURE; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,574
DelOld( PProfileList list, PProfile profile ) { PProfile *old, current; old = list; current = *old; while ( current ) { if ( current == profile ) { *old = current->link; return; } old = &current->link; current = *old; } /* we should never get there, unless the profile was not part of */ /* the list. */ }
DoS Overflow
0
DelOld( PProfileList list, PProfile profile ) { PProfile *old, current; old = list; current = *old; while ( current ) { if ( current == profile ) { *old = current->link; return; } old = &current->link; current = *old; } /* we should never get there, unless the profile was not part of */ /* the list. */ }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,575
Draw_Sweep( RAS_ARG ) { Short y, y_change, y_height; PProfile P, Q, P_Left, P_Right; Short min_Y, max_Y, top, bottom, dropouts; Long x1, x2, xs, e1, e2; TProfileList waiting; TProfileList draw_left, draw_right; /* initialize empty linked lists */ Init_Linked( &waiting ); Init_Linked( &draw_left ); Init_Linked( &draw_right ); /* first, compute min and max Y */ P = ras.fProfile; max_Y = (Short)TRUNC( ras.minY ); min_Y = (Short)TRUNC( ras.maxY ); while ( P ) { Q = P->link; bottom = (Short)P->start; top = (Short)( P->start + P->height - 1 ); if ( min_Y > bottom ) min_Y = bottom; if ( max_Y < top ) max_Y = top; P->X = 0; InsNew( &waiting, P ); P = Q; } /* check the Y-turns */ if ( ras.numTurns == 0 ) { ras.error = FT_THROW( Invalid ); return FAILURE; } /* now initialize the sweep */ ras.Proc_Sweep_Init( RAS_VARS &min_Y, &max_Y ); /* then compute the distance of each profile from min_Y */ P = waiting; while ( P ) { P->countL = (UShort)( P->start - min_Y ); P = P->link; } /* let's go */ y = min_Y; y_height = 0; if ( ras.numTurns > 0 && ras.sizeBuff[-ras.numTurns] == min_Y ) ras.numTurns--; while ( ras.numTurns > 0 ) { /* check waiting list for new activations */ P = waiting; while ( P ) { Q = P->link; P->countL -= y_height; if ( P->countL == 0 ) { DelOld( &waiting, P ); if ( P->flags & Flow_Up ) InsNew( &draw_left, P ); else InsNew( &draw_right, P ); } P = Q; } /* sort the drawing lists */ Sort( &draw_left ); Sort( &draw_right ); y_change = (Short)ras.sizeBuff[-ras.numTurns--]; y_height = (Short)( y_change - y ); while ( y < y_change ) { /* let's trace */ dropouts = 0; P_Left = draw_left; P_Right = draw_right; while ( P_Left ) { x1 = P_Left ->X; x2 = P_Right->X; if ( x1 > x2 ) { xs = x1; x1 = x2; x2 = xs; } e1 = FLOOR( x1 ); e2 = CEILING( x2 ); if ( x2 - x1 <= ras.precision && e1 != x1 && e2 != x2 ) { if ( e1 > e2 || e2 == e1 + ras.precision ) { Int dropOutControl = P_Left->flags & 7; if ( dropOutControl != 2 ) { /* a drop-out was detected */ P_Left ->X = x1; P_Right->X = x2; /* mark profile for drop-out processing */ P_Left->countL = 1; dropouts++; } goto Skip_To_Next; } } ras.Proc_Sweep_Span( RAS_VARS y, x1, x2, P_Left, P_Right ); Skip_To_Next: P_Left = P_Left->link; P_Right = P_Right->link; } /* handle drop-outs _after_ the span drawing -- */ /* drop-out processing has been moved out of the loop */ /* for performance tuning */ if ( dropouts > 0 ) goto Scan_DropOuts; Next_Line: ras.Proc_Sweep_Step( RAS_VAR ); y++; if ( y < y_change ) { Sort( &draw_left ); Sort( &draw_right ); } } /* now finalize the profiles that need it */ P = draw_left; while ( P ) { Q = P->link; if ( P->height == 0 ) DelOld( &draw_left, P ); P = Q; } P = draw_right; while ( P ) { Q = P->link; if ( P->height == 0 ) DelOld( &draw_right, P ); P = Q; } } /* for gray-scaling, flush the bitmap scanline cache */ while ( y <= max_Y ) { ras.Proc_Sweep_Step( RAS_VAR ); y++; } return SUCCESS; Scan_DropOuts: P_Left = draw_left; P_Right = draw_right; while ( P_Left ) { if ( P_Left->countL ) { P_Left->countL = 0; #if 0 dropouts--; /* -- this is useful when debugging only */ #endif ras.Proc_Sweep_Drop( RAS_VARS y, P_Left->X, P_Right->X, P_Left, P_Right ); } P_Left = P_Left->link; P_Right = P_Right->link; } goto Next_Line; }
DoS Overflow
0
Draw_Sweep( RAS_ARG ) { Short y, y_change, y_height; PProfile P, Q, P_Left, P_Right; Short min_Y, max_Y, top, bottom, dropouts; Long x1, x2, xs, e1, e2; TProfileList waiting; TProfileList draw_left, draw_right; /* initialize empty linked lists */ Init_Linked( &waiting ); Init_Linked( &draw_left ); Init_Linked( &draw_right ); /* first, compute min and max Y */ P = ras.fProfile; max_Y = (Short)TRUNC( ras.minY ); min_Y = (Short)TRUNC( ras.maxY ); while ( P ) { Q = P->link; bottom = (Short)P->start; top = (Short)( P->start + P->height - 1 ); if ( min_Y > bottom ) min_Y = bottom; if ( max_Y < top ) max_Y = top; P->X = 0; InsNew( &waiting, P ); P = Q; } /* check the Y-turns */ if ( ras.numTurns == 0 ) { ras.error = FT_THROW( Invalid ); return FAILURE; } /* now initialize the sweep */ ras.Proc_Sweep_Init( RAS_VARS &min_Y, &max_Y ); /* then compute the distance of each profile from min_Y */ P = waiting; while ( P ) { P->countL = (UShort)( P->start - min_Y ); P = P->link; } /* let's go */ y = min_Y; y_height = 0; if ( ras.numTurns > 0 && ras.sizeBuff[-ras.numTurns] == min_Y ) ras.numTurns--; while ( ras.numTurns > 0 ) { /* check waiting list for new activations */ P = waiting; while ( P ) { Q = P->link; P->countL -= y_height; if ( P->countL == 0 ) { DelOld( &waiting, P ); if ( P->flags & Flow_Up ) InsNew( &draw_left, P ); else InsNew( &draw_right, P ); } P = Q; } /* sort the drawing lists */ Sort( &draw_left ); Sort( &draw_right ); y_change = (Short)ras.sizeBuff[-ras.numTurns--]; y_height = (Short)( y_change - y ); while ( y < y_change ) { /* let's trace */ dropouts = 0; P_Left = draw_left; P_Right = draw_right; while ( P_Left ) { x1 = P_Left ->X; x2 = P_Right->X; if ( x1 > x2 ) { xs = x1; x1 = x2; x2 = xs; } e1 = FLOOR( x1 ); e2 = CEILING( x2 ); if ( x2 - x1 <= ras.precision && e1 != x1 && e2 != x2 ) { if ( e1 > e2 || e2 == e1 + ras.precision ) { Int dropOutControl = P_Left->flags & 7; if ( dropOutControl != 2 ) { /* a drop-out was detected */ P_Left ->X = x1; P_Right->X = x2; /* mark profile for drop-out processing */ P_Left->countL = 1; dropouts++; } goto Skip_To_Next; } } ras.Proc_Sweep_Span( RAS_VARS y, x1, x2, P_Left, P_Right ); Skip_To_Next: P_Left = P_Left->link; P_Right = P_Right->link; } /* handle drop-outs _after_ the span drawing -- */ /* drop-out processing has been moved out of the loop */ /* for performance tuning */ if ( dropouts > 0 ) goto Scan_DropOuts; Next_Line: ras.Proc_Sweep_Step( RAS_VAR ); y++; if ( y < y_change ) { Sort( &draw_left ); Sort( &draw_right ); } } /* now finalize the profiles that need it */ P = draw_left; while ( P ) { Q = P->link; if ( P->height == 0 ) DelOld( &draw_left, P ); P = Q; } P = draw_right; while ( P ) { Q = P->link; if ( P->height == 0 ) DelOld( &draw_right, P ); P = Q; } } /* for gray-scaling, flush the bitmap scanline cache */ while ( y <= max_Y ) { ras.Proc_Sweep_Step( RAS_VAR ); y++; } return SUCCESS; Scan_DropOuts: P_Left = draw_left; P_Right = draw_right; while ( P_Left ) { if ( P_Left->countL ) { P_Left->countL = 0; #if 0 dropouts--; /* -- this is useful when debugging only */ #endif ras.Proc_Sweep_Drop( RAS_VARS y, P_Left->X, P_Right->X, P_Left, P_Right ); } P_Left = P_Left->link; P_Right = P_Right->link; } goto Next_Line; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,576
End_Profile( RAS_ARGS Bool overshoot ) { Long h; h = (Long)( ras.top - ras.cProfile->offset ); if ( h < 0 ) { FT_ERROR(( "End_Profile: negative height encountered\n" )); ras.error = FT_THROW( Neg_Height ); return FAILURE; } if ( h > 0 ) { PProfile oldProfile; FT_TRACE6(( "Ending profile %p, start = %ld, height = %ld\n", ras.cProfile, ras.cProfile->start, h )); ras.cProfile->height = h; if ( overshoot ) { if ( ras.cProfile->flags & Flow_Up ) ras.cProfile->flags |= Overshoot_Top; else ras.cProfile->flags |= Overshoot_Bottom; } oldProfile = ras.cProfile; ras.cProfile = (PProfile)ras.top; ras.top += AlignProfileSize; ras.cProfile->height = 0; ras.cProfile->offset = ras.top; oldProfile->next = ras.cProfile; ras.num_Profs++; } if ( ras.top >= ras.maxBuff ) { FT_TRACE1(( "overflow in End_Profile\n" )); ras.error = FT_THROW( Overflow ); return FAILURE; } ras.joint = FALSE; return SUCCESS; }
DoS Overflow
0
End_Profile( RAS_ARGS Bool overshoot ) { Long h; h = (Long)( ras.top - ras.cProfile->offset ); if ( h < 0 ) { FT_ERROR(( "End_Profile: negative height encountered\n" )); ras.error = FT_THROW( Neg_Height ); return FAILURE; } if ( h > 0 ) { PProfile oldProfile; FT_TRACE6(( "Ending profile %p, start = %ld, height = %ld\n", ras.cProfile, ras.cProfile->start, h )); ras.cProfile->height = h; if ( overshoot ) { if ( ras.cProfile->flags & Flow_Up ) ras.cProfile->flags |= Overshoot_Top; else ras.cProfile->flags |= Overshoot_Bottom; } oldProfile = ras.cProfile; ras.cProfile = (PProfile)ras.top; ras.top += AlignProfileSize; ras.cProfile->height = 0; ras.cProfile->offset = ras.top; oldProfile->next = ras.cProfile; ras.num_Profs++; } if ( ras.top >= ras.maxBuff ) { FT_TRACE1(( "overflow in End_Profile\n" )); ras.error = FT_THROW( Overflow ); return FAILURE; } ras.joint = FALSE; return SUCCESS; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,577
Finalize_Profile_Table( RAS_ARG ) { UShort n; PProfile p; n = ras.num_Profs; p = ras.fProfile; if ( n > 1 && p ) { while ( n > 0 ) { Int bottom, top; if ( n > 1 ) p->link = (PProfile)( p->offset + p->height ); else p->link = NULL; if ( p->flags & Flow_Up ) { bottom = (Int)p->start; top = (Int)( p->start + p->height - 1 ); } else { bottom = (Int)( p->start - p->height + 1 ); top = (Int)p->start; p->start = bottom; p->offset += p->height - 1; } if ( Insert_Y_Turn( RAS_VARS bottom ) || Insert_Y_Turn( RAS_VARS top + 1 ) ) return FAILURE; p = p->link; n--; } } else ras.fProfile = NULL; return SUCCESS; }
DoS Overflow
0
Finalize_Profile_Table( RAS_ARG ) { UShort n; PProfile p; n = ras.num_Profs; p = ras.fProfile; if ( n > 1 && p ) { while ( n > 0 ) { Int bottom, top; if ( n > 1 ) p->link = (PProfile)( p->offset + p->height ); else p->link = NULL; if ( p->flags & Flow_Up ) { bottom = (Int)p->start; top = (Int)( p->start + p->height - 1 ); } else { bottom = (Int)( p->start - p->height + 1 ); top = (Int)p->start; p->start = bottom; p->offset += p->height - 1; } if ( Insert_Y_Turn( RAS_VARS bottom ) || Insert_Y_Turn( RAS_VARS top + 1 ) ) return FAILURE; p = p->link; n--; } } else ras.fProfile = NULL; return SUCCESS; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,578
Horizontal_Gray_Sweep_Span( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { /* nothing, really */ FT_UNUSED_RASTER; FT_UNUSED( y ); FT_UNUSED( x1 ); FT_UNUSED( x2 ); FT_UNUSED( left ); FT_UNUSED( right ); }
DoS Overflow
0
Horizontal_Gray_Sweep_Span( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { /* nothing, really */ FT_UNUSED_RASTER; FT_UNUSED( y ); FT_UNUSED( x1 ); FT_UNUSED( x2 ); FT_UNUSED( left ); FT_UNUSED( right ); }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,579
Horizontal_Sweep_Init( RAS_ARGS Short* min, Short* max ) { /* nothing, really */ FT_UNUSED_RASTER; FT_UNUSED( min ); FT_UNUSED( max ); }
DoS Overflow
0
Horizontal_Sweep_Init( RAS_ARGS Short* min, Short* max ) { /* nothing, really */ FT_UNUSED_RASTER; FT_UNUSED( min ); FT_UNUSED( max ); }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,580
Horizontal_Sweep_Step( RAS_ARG ) { /* Nothing, really */ FT_UNUSED_RASTER; }
DoS Overflow
0
Horizontal_Sweep_Step( RAS_ARG ) { /* Nothing, really */ FT_UNUSED_RASTER; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,581
Init_Linked( TProfileList* l ) { *l = NULL; }
DoS Overflow
0
Init_Linked( TProfileList* l ) { *l = NULL; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,582
InsNew( PProfileList list, PProfile profile ) { PProfile *old, current; Long x; old = list; current = *old; x = profile->X; while ( current ) { if ( x < current->X ) break; old = &current->link; current = *old; } profile->link = current; *old = profile; }
DoS Overflow
0
InsNew( PProfileList list, PProfile profile ) { PProfile *old, current; Long x; old = list; current = *old; x = profile->X; while ( current ) { if ( x < current->X ) break; old = &current->link; current = *old; } profile->link = current; *old = profile; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,583
Insert_Y_Turn( RAS_ARGS Int y ) { PLong y_turns; Int n; n = ras.numTurns - 1; y_turns = ras.sizeBuff - ras.numTurns; /* look for first y value that is <= */ while ( n >= 0 && y < y_turns[n] ) n--; /* if it is <, simply insert it, ignore if == */ if ( n >= 0 && y > y_turns[n] ) while ( n >= 0 ) { Int y2 = (Int)y_turns[n]; y_turns[n] = y; y = y2; n--; } if ( n < 0 ) { ras.maxBuff--; if ( ras.maxBuff <= ras.top ) { ras.error = FT_THROW( Overflow ); return FAILURE; } ras.numTurns++; ras.sizeBuff[-ras.numTurns] = y; } return SUCCESS; }
DoS Overflow
0
Insert_Y_Turn( RAS_ARGS Int y ) { PLong y_turns; Int n; n = ras.numTurns - 1; y_turns = ras.sizeBuff - ras.numTurns; /* look for first y value that is <= */ while ( n >= 0 && y < y_turns[n] ) n--; /* if it is <, simply insert it, ignore if == */ if ( n >= 0 && y > y_turns[n] ) while ( n >= 0 ) { Int y2 = (Int)y_turns[n]; y_turns[n] = y; y = y2; n--; } if ( n < 0 ) { ras.maxBuff--; if ( ras.maxBuff <= ras.top ) { ras.error = FT_THROW( Overflow ); return FAILURE; } ras.numTurns++; ras.sizeBuff[-ras.numTurns] = y; } return SUCCESS; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,584
Line_To( RAS_ARGS Long x, Long y ) { /* First, detect a change of direction */ switch ( ras.state ) { case Unknown_State: if ( y > ras.lastY ) { if ( New_Profile( RAS_VARS Ascending_State, IS_BOTTOM_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } else { if ( y < ras.lastY ) if ( New_Profile( RAS_VARS Descending_State, IS_TOP_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; case Ascending_State: if ( y < ras.lastY ) { if ( End_Profile( RAS_VARS IS_TOP_OVERSHOOT( ras.lastY ) ) || New_Profile( RAS_VARS Descending_State, IS_TOP_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; case Descending_State: if ( y > ras.lastY ) { if ( End_Profile( RAS_VARS IS_BOTTOM_OVERSHOOT( ras.lastY ) ) || New_Profile( RAS_VARS Ascending_State, IS_BOTTOM_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; default: ; } /* Then compute the lines */ switch ( ras.state ) { case Ascending_State: if ( Line_Up( RAS_VARS ras.lastX, ras.lastY, x, y, ras.minY, ras.maxY ) ) return FAILURE; break; case Descending_State: if ( Line_Down( RAS_VARS ras.lastX, ras.lastY, x, y, ras.minY, ras.maxY ) ) return FAILURE; break; default: ; } ras.lastX = x; ras.lastY = y; return SUCCESS; }
DoS Overflow
0
Line_To( RAS_ARGS Long x, Long y ) { /* First, detect a change of direction */ switch ( ras.state ) { case Unknown_State: if ( y > ras.lastY ) { if ( New_Profile( RAS_VARS Ascending_State, IS_BOTTOM_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } else { if ( y < ras.lastY ) if ( New_Profile( RAS_VARS Descending_State, IS_TOP_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; case Ascending_State: if ( y < ras.lastY ) { if ( End_Profile( RAS_VARS IS_TOP_OVERSHOOT( ras.lastY ) ) || New_Profile( RAS_VARS Descending_State, IS_TOP_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; case Descending_State: if ( y > ras.lastY ) { if ( End_Profile( RAS_VARS IS_BOTTOM_OVERSHOOT( ras.lastY ) ) || New_Profile( RAS_VARS Ascending_State, IS_BOTTOM_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; default: ; } /* Then compute the lines */ switch ( ras.state ) { case Ascending_State: if ( Line_Up( RAS_VARS ras.lastX, ras.lastY, x, y, ras.minY, ras.maxY ) ) return FAILURE; break; case Descending_State: if ( Line_Down( RAS_VARS ras.lastX, ras.lastY, x, y, ras.minY, ras.maxY ) ) return FAILURE; break; default: ; } ras.lastX = x; ras.lastY = y; return SUCCESS; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,585
Line_Up( RAS_ARGS Long x1, Long y1, Long x2, Long y2, Long miny, Long maxy ) { Long Dx, Dy; Int e1, e2, f1, f2, size; /* XXX: is `Short' sufficient? */ Long Ix, Rx, Ax; PLong top; Dx = x2 - x1; Dy = y2 - y1; if ( Dy <= 0 || y2 < miny || y1 > maxy ) return SUCCESS; if ( y1 < miny ) { /* Take care: miny-y1 can be a very large value; we use */ /* a slow MulDiv function to avoid clipping bugs */ x1 += SMulDiv( Dx, miny - y1, Dy ); e1 = (Int)TRUNC( miny ); f1 = 0; } else { e1 = (Int)TRUNC( y1 ); f1 = (Int)FRAC( y1 ); } if ( y2 > maxy ) { /* x2 += FMulDiv( Dx, maxy - y2, Dy ); UNNECESSARY */ e2 = (Int)TRUNC( maxy ); f2 = 0; } else { e2 = (Int)TRUNC( y2 ); f2 = (Int)FRAC( y2 ); } if ( f1 > 0 ) { if ( e1 == e2 ) return SUCCESS; else { x1 += SMulDiv( Dx, ras.precision - f1, Dy ); e1 += 1; } } else if ( ras.joint ) { ras.top--; ras.joint = FALSE; } ras.joint = (char)( f2 == 0 ); if ( ras.fresh ) { ras.cProfile->start = e1; ras.fresh = FALSE; } size = e2 - e1 + 1; if ( ras.top + size >= ras.maxBuff ) { ras.error = FT_THROW( Overflow ); return FAILURE; } if ( Dx > 0 ) { Ix = SMulDiv_No_Round( ras.precision, Dx, Dy ); Rx = ( ras.precision * Dx ) % Dy; Dx = 1; } else { Ix = -SMulDiv_No_Round( ras.precision, -Dx, Dy ); Rx = ( ras.precision * -Dx ) % Dy; Dx = -1; } Ax = -Dy; top = ras.top; while ( size > 0 ) { *top++ = x1; x1 += Ix; Ax += Rx; if ( Ax >= 0 ) { Ax -= Dy; x1 += Dx; } size--; } ras.top = top; return SUCCESS; }
DoS Overflow
0
Line_Up( RAS_ARGS Long x1, Long y1, Long x2, Long y2, Long miny, Long maxy ) { Long Dx, Dy; Int e1, e2, f1, f2, size; /* XXX: is `Short' sufficient? */ Long Ix, Rx, Ax; PLong top; Dx = x2 - x1; Dy = y2 - y1; if ( Dy <= 0 || y2 < miny || y1 > maxy ) return SUCCESS; if ( y1 < miny ) { /* Take care: miny-y1 can be a very large value; we use */ /* a slow MulDiv function to avoid clipping bugs */ x1 += SMulDiv( Dx, miny - y1, Dy ); e1 = (Int)TRUNC( miny ); f1 = 0; } else { e1 = (Int)TRUNC( y1 ); f1 = (Int)FRAC( y1 ); } if ( y2 > maxy ) { /* x2 += FMulDiv( Dx, maxy - y2, Dy ); UNNECESSARY */ e2 = (Int)TRUNC( maxy ); f2 = 0; } else { e2 = (Int)TRUNC( y2 ); f2 = (Int)FRAC( y2 ); } if ( f1 > 0 ) { if ( e1 == e2 ) return SUCCESS; else { x1 += SMulDiv( Dx, ras.precision - f1, Dy ); e1 += 1; } } else if ( ras.joint ) { ras.top--; ras.joint = FALSE; } ras.joint = (char)( f2 == 0 ); if ( ras.fresh ) { ras.cProfile->start = e1; ras.fresh = FALSE; } size = e2 - e1 + 1; if ( ras.top + size >= ras.maxBuff ) { ras.error = FT_THROW( Overflow ); return FAILURE; } if ( Dx > 0 ) { Ix = SMulDiv_No_Round( ras.precision, Dx, Dy ); Rx = ( ras.precision * Dx ) % Dy; Dx = 1; } else { Ix = -SMulDiv_No_Round( ras.precision, -Dx, Dy ); Rx = ( ras.precision * -Dx ) % Dy; Dx = -1; } Ax = -Dy; top = ras.top; while ( size > 0 ) { *top++ = x1; x1 += Ix; Ax += Rx; if ( Ax >= 0 ) { Ax -= Dy; x1 += Dx; } size--; } ras.top = top; return SUCCESS; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,586
New_Profile( RAS_ARGS TStates aState, Bool overshoot ) { if ( !ras.fProfile ) { ras.cProfile = (PProfile)ras.top; ras.fProfile = ras.cProfile; ras.top += AlignProfileSize; } if ( ras.top >= ras.maxBuff ) { ras.error = FT_THROW( Overflow ); return FAILURE; } ras.cProfile->flags = 0; ras.cProfile->start = 0; ras.cProfile->height = 0; ras.cProfile->offset = ras.top; ras.cProfile->link = (PProfile)0; ras.cProfile->next = (PProfile)0; ras.cProfile->flags = ras.dropOutControl; switch ( aState ) { case Ascending_State: ras.cProfile->flags |= Flow_Up; if ( overshoot ) ras.cProfile->flags |= Overshoot_Bottom; FT_TRACE6(( "New ascending profile = %p\n", ras.cProfile )); break; case Descending_State: if ( overshoot ) ras.cProfile->flags |= Overshoot_Top; FT_TRACE6(( "New descending profile = %p\n", ras.cProfile )); break; default: FT_ERROR(( "New_Profile: invalid profile direction\n" )); ras.error = FT_THROW( Invalid ); return FAILURE; } if ( !ras.gProfile ) ras.gProfile = ras.cProfile; ras.state = aState; ras.fresh = TRUE; ras.joint = FALSE; return SUCCESS; }
DoS Overflow
0
New_Profile( RAS_ARGS TStates aState, Bool overshoot ) { if ( !ras.fProfile ) { ras.cProfile = (PProfile)ras.top; ras.fProfile = ras.cProfile; ras.top += AlignProfileSize; } if ( ras.top >= ras.maxBuff ) { ras.error = FT_THROW( Overflow ); return FAILURE; } ras.cProfile->flags = 0; ras.cProfile->start = 0; ras.cProfile->height = 0; ras.cProfile->offset = ras.top; ras.cProfile->link = (PProfile)0; ras.cProfile->next = (PProfile)0; ras.cProfile->flags = ras.dropOutControl; switch ( aState ) { case Ascending_State: ras.cProfile->flags |= Flow_Up; if ( overshoot ) ras.cProfile->flags |= Overshoot_Bottom; FT_TRACE6(( "New ascending profile = %p\n", ras.cProfile )); break; case Descending_State: if ( overshoot ) ras.cProfile->flags |= Overshoot_Top; FT_TRACE6(( "New descending profile = %p\n", ras.cProfile )); break; default: FT_ERROR(( "New_Profile: invalid profile direction\n" )); ras.error = FT_THROW( Invalid ); return FAILURE; } if ( !ras.gProfile ) ras.gProfile = ras.cProfile; ras.state = aState; ras.fresh = TRUE; ras.joint = FALSE; return SUCCESS; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,587
Render_Glyph( RAS_ARG ) { FT_Error error; Set_High_Precision( RAS_VARS ras.outline.flags & FT_OUTLINE_HIGH_PRECISION ); ras.scale_shift = ras.precision_shift; if ( ras.outline.flags & FT_OUTLINE_IGNORE_DROPOUTS ) ras.dropOutControl = 2; else { if ( ras.outline.flags & FT_OUTLINE_SMART_DROPOUTS ) ras.dropOutControl = 4; else ras.dropOutControl = 0; if ( !( ras.outline.flags & FT_OUTLINE_INCLUDE_STUBS ) ) ras.dropOutControl += 1; } ras.second_pass = (FT_Byte)( !( ras.outline.flags & FT_OUTLINE_SINGLE_PASS ) ); /* Vertical Sweep */ ras.Proc_Sweep_Init = Vertical_Sweep_Init; ras.Proc_Sweep_Span = Vertical_Sweep_Span; ras.Proc_Sweep_Drop = Vertical_Sweep_Drop; ras.Proc_Sweep_Step = Vertical_Sweep_Step; ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = (short)( ras.target.rows - 1 ); ras.bWidth = (unsigned short)ras.target.width; ras.bTarget = (Byte*)ras.target.buffer; if ( ( error = Render_Single_Pass( RAS_VARS 0 ) ) != 0 ) return error; /* Horizontal Sweep */ if ( ras.second_pass && ras.dropOutControl != 2 ) { ras.Proc_Sweep_Init = Horizontal_Sweep_Init; ras.Proc_Sweep_Span = Horizontal_Sweep_Span; ras.Proc_Sweep_Drop = Horizontal_Sweep_Drop; ras.Proc_Sweep_Step = Horizontal_Sweep_Step; ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = (short)( ras.target.width - 1 ); if ( ( error = Render_Single_Pass( RAS_VARS 1 ) ) != 0 ) return error; } return Raster_Err_None; }
DoS Overflow
0
Render_Glyph( RAS_ARG ) { FT_Error error; Set_High_Precision( RAS_VARS ras.outline.flags & FT_OUTLINE_HIGH_PRECISION ); ras.scale_shift = ras.precision_shift; if ( ras.outline.flags & FT_OUTLINE_IGNORE_DROPOUTS ) ras.dropOutControl = 2; else { if ( ras.outline.flags & FT_OUTLINE_SMART_DROPOUTS ) ras.dropOutControl = 4; else ras.dropOutControl = 0; if ( !( ras.outline.flags & FT_OUTLINE_INCLUDE_STUBS ) ) ras.dropOutControl += 1; } ras.second_pass = (FT_Byte)( !( ras.outline.flags & FT_OUTLINE_SINGLE_PASS ) ); /* Vertical Sweep */ ras.Proc_Sweep_Init = Vertical_Sweep_Init; ras.Proc_Sweep_Span = Vertical_Sweep_Span; ras.Proc_Sweep_Drop = Vertical_Sweep_Drop; ras.Proc_Sweep_Step = Vertical_Sweep_Step; ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = (short)( ras.target.rows - 1 ); ras.bWidth = (unsigned short)ras.target.width; ras.bTarget = (Byte*)ras.target.buffer; if ( ( error = Render_Single_Pass( RAS_VARS 0 ) ) != 0 ) return error; /* Horizontal Sweep */ if ( ras.second_pass && ras.dropOutControl != 2 ) { ras.Proc_Sweep_Init = Horizontal_Sweep_Init; ras.Proc_Sweep_Span = Horizontal_Sweep_Span; ras.Proc_Sweep_Drop = Horizontal_Sweep_Drop; ras.Proc_Sweep_Step = Horizontal_Sweep_Step; ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = (short)( ras.target.width - 1 ); if ( ( error = Render_Single_Pass( RAS_VARS 1 ) ) != 0 ) return error; } return Raster_Err_None; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,588
Render_Gray_Glyph( RAS_ARG ) { Long pixel_width; FT_Error error; Set_High_Precision( RAS_VARS ras.outline.flags & FT_OUTLINE_HIGH_PRECISION ); ras.scale_shift = ras.precision_shift + 1; if ( ras.outline.flags & FT_OUTLINE_IGNORE_DROPOUTS ) ras.dropOutControl = 2; else { if ( ras.outline.flags & FT_OUTLINE_SMART_DROPOUTS ) ras.dropOutControl = 4; else ras.dropOutControl = 0; if ( !( ras.outline.flags & FT_OUTLINE_INCLUDE_STUBS ) ) ras.dropOutControl += 1; } ras.second_pass = !( ras.outline.flags & FT_OUTLINE_SINGLE_PASS ); /* Vertical Sweep */ ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = 2 * ras.target.rows - 1; ras.bWidth = ras.gray_width; pixel_width = 2 * ( ( ras.target.width + 3 ) >> 2 ); if ( ras.bWidth > pixel_width ) ras.bWidth = pixel_width; ras.bWidth = ras.bWidth * 8; ras.bTarget = (Byte*)ras.gray_lines; ras.gTarget = (Byte*)ras.target.buffer; ras.Proc_Sweep_Init = Vertical_Gray_Sweep_Init; ras.Proc_Sweep_Span = Vertical_Sweep_Span; ras.Proc_Sweep_Drop = Vertical_Sweep_Drop; ras.Proc_Sweep_Step = Vertical_Gray_Sweep_Step; error = Render_Single_Pass( RAS_VARS 0 ); if ( error ) return error; /* Horizontal Sweep */ if ( ras.second_pass && ras.dropOutControl != 2 ) { ras.Proc_Sweep_Init = Horizontal_Sweep_Init; ras.Proc_Sweep_Span = Horizontal_Gray_Sweep_Span; ras.Proc_Sweep_Drop = Horizontal_Gray_Sweep_Drop; ras.Proc_Sweep_Step = Horizontal_Sweep_Step; ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = ras.target.width * 2 - 1; error = Render_Single_Pass( RAS_VARS 1 ); if ( error ) return error; } return Raster_Err_None; }
DoS Overflow
0
Render_Gray_Glyph( RAS_ARG ) { Long pixel_width; FT_Error error; Set_High_Precision( RAS_VARS ras.outline.flags & FT_OUTLINE_HIGH_PRECISION ); ras.scale_shift = ras.precision_shift + 1; if ( ras.outline.flags & FT_OUTLINE_IGNORE_DROPOUTS ) ras.dropOutControl = 2; else { if ( ras.outline.flags & FT_OUTLINE_SMART_DROPOUTS ) ras.dropOutControl = 4; else ras.dropOutControl = 0; if ( !( ras.outline.flags & FT_OUTLINE_INCLUDE_STUBS ) ) ras.dropOutControl += 1; } ras.second_pass = !( ras.outline.flags & FT_OUTLINE_SINGLE_PASS ); /* Vertical Sweep */ ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = 2 * ras.target.rows - 1; ras.bWidth = ras.gray_width; pixel_width = 2 * ( ( ras.target.width + 3 ) >> 2 ); if ( ras.bWidth > pixel_width ) ras.bWidth = pixel_width; ras.bWidth = ras.bWidth * 8; ras.bTarget = (Byte*)ras.gray_lines; ras.gTarget = (Byte*)ras.target.buffer; ras.Proc_Sweep_Init = Vertical_Gray_Sweep_Init; ras.Proc_Sweep_Span = Vertical_Sweep_Span; ras.Proc_Sweep_Drop = Vertical_Sweep_Drop; ras.Proc_Sweep_Step = Vertical_Gray_Sweep_Step; error = Render_Single_Pass( RAS_VARS 0 ); if ( error ) return error; /* Horizontal Sweep */ if ( ras.second_pass && ras.dropOutControl != 2 ) { ras.Proc_Sweep_Init = Horizontal_Sweep_Init; ras.Proc_Sweep_Span = Horizontal_Gray_Sweep_Span; ras.Proc_Sweep_Drop = Horizontal_Gray_Sweep_Drop; ras.Proc_Sweep_Step = Horizontal_Sweep_Step; ras.band_top = 0; ras.band_stack[0].y_min = 0; ras.band_stack[0].y_max = ras.target.width * 2 - 1; error = Render_Single_Pass( RAS_VARS 1 ); if ( error ) return error; } return Raster_Err_None; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,589
Render_Single_Pass( RAS_ARGS Bool flipped ) { Short i, j, k; while ( ras.band_top >= 0 ) { ras.maxY = (Long)ras.band_stack[ras.band_top].y_max * ras.precision; ras.minY = (Long)ras.band_stack[ras.band_top].y_min * ras.precision; ras.top = ras.buff; ras.error = Raster_Err_None; if ( Convert_Glyph( RAS_VARS flipped ) ) { if ( ras.error != Raster_Err_Overflow ) return FAILURE; ras.error = Raster_Err_None; /* sub-banding */ #ifdef DEBUG_RASTER ClearBand( RAS_VARS TRUNC( ras.minY ), TRUNC( ras.maxY ) ); #endif i = ras.band_stack[ras.band_top].y_min; j = ras.band_stack[ras.band_top].y_max; k = (Short)( ( i + j ) / 2 ); if ( ras.band_top >= 7 || k < i ) { ras.band_top = 0; ras.error = FT_THROW( Invalid ); return ras.error; } ras.band_stack[ras.band_top + 1].y_min = k; ras.band_stack[ras.band_top + 1].y_max = j; ras.band_stack[ras.band_top].y_max = (Short)( k - 1 ); ras.band_top++; } else { if ( ras.fProfile ) if ( Draw_Sweep( RAS_VAR ) ) return ras.error; ras.band_top--; } } return SUCCESS; }
DoS Overflow
0
Render_Single_Pass( RAS_ARGS Bool flipped ) { Short i, j, k; while ( ras.band_top >= 0 ) { ras.maxY = (Long)ras.band_stack[ras.band_top].y_max * ras.precision; ras.minY = (Long)ras.band_stack[ras.band_top].y_min * ras.precision; ras.top = ras.buff; ras.error = Raster_Err_None; if ( Convert_Glyph( RAS_VARS flipped ) ) { if ( ras.error != Raster_Err_Overflow ) return FAILURE; ras.error = Raster_Err_None; /* sub-banding */ #ifdef DEBUG_RASTER ClearBand( RAS_VARS TRUNC( ras.minY ), TRUNC( ras.maxY ) ); #endif i = ras.band_stack[ras.band_top].y_min; j = ras.band_stack[ras.band_top].y_max; k = (Short)( ( i + j ) / 2 ); if ( ras.band_top >= 7 || k < i ) { ras.band_top = 0; ras.error = FT_THROW( Invalid ); return ras.error; } ras.band_stack[ras.band_top + 1].y_min = k; ras.band_stack[ras.band_top + 1].y_max = j; ras.band_stack[ras.band_top].y_max = (Short)( k - 1 ); ras.band_top++; } else { if ( ras.fProfile ) if ( Draw_Sweep( RAS_VAR ) ) return ras.error; ras.band_top--; } } return SUCCESS; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,590
Set_High_Precision( RAS_ARGS Int High ) { /* * `precision_step' is used in `Bezier_Up' to decide when to split a * given y-monotonous Bezier arc that crosses a scanline before * approximating it as a straight segment. The default value of 32 (for * low accuracy) corresponds to * * 32 / 64 == 0.5 pixels , * * while for the high accuracy case we have * * 256/ (1 << 12) = 0.0625 pixels . * * `precision_jitter' is an epsilon threshold used in * `Vertical_Sweep_Span' to deal with small imperfections in the Bezier * decomposition (after all, we are working with approximations only); * it avoids switching on additional pixels which would cause artifacts * otherwise. * * The value of `precision_jitter' has been determined heuristically. * */ if ( High ) { ras.precision_bits = 12; ras.precision_step = 256; ras.precision_jitter = 30; } else { ras.precision_bits = 6; ras.precision_step = 32; ras.precision_jitter = 2; } FT_TRACE6(( "Set_High_Precision(%s)\n", High ? "true" : "false" )); ras.precision = 1 << ras.precision_bits; ras.precision_half = ras.precision / 2; ras.precision_shift = ras.precision_bits - Pixel_Bits; }
DoS Overflow
0
Set_High_Precision( RAS_ARGS Int High ) { /* * `precision_step' is used in `Bezier_Up' to decide when to split a * given y-monotonous Bezier arc that crosses a scanline before * approximating it as a straight segment. The default value of 32 (for * low accuracy) corresponds to * * 32 / 64 == 0.5 pixels , * * while for the high accuracy case we have * * 256/ (1 << 12) = 0.0625 pixels . * * `precision_jitter' is an epsilon threshold used in * `Vertical_Sweep_Span' to deal with small imperfections in the Bezier * decomposition (after all, we are working with approximations only); * it avoids switching on additional pixels which would cause artifacts * otherwise. * * The value of `precision_jitter' has been determined heuristically. * */ if ( High ) { ras.precision_bits = 12; ras.precision_step = 256; ras.precision_jitter = 30; } else { ras.precision_bits = 6; ras.precision_step = 32; ras.precision_jitter = 2; } FT_TRACE6(( "Set_High_Precision(%s)\n", High ? "true" : "false" )); ras.precision = 1 << ras.precision_bits; ras.precision_half = ras.precision / 2; ras.precision_shift = ras.precision_bits - Pixel_Bits; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,591
Sort( PProfileList list ) { PProfile *old, current, next; /* First, set the new X coordinate of each profile */ current = *list; while ( current ) { current->X = *current->offset; current->offset += current->flags & Flow_Up ? 1 : -1; current->height--; current = current->link; } /* Then sort them */ old = list; current = *old; if ( !current ) return; next = current->link; while ( next ) { if ( current->X <= next->X ) { old = &current->link; current = *old; if ( !current ) return; } else { *old = next; current->link = next->link; next->link = current; old = list; current = *old; } next = current->link; } }
DoS Overflow
0
Sort( PProfileList list ) { PProfile *old, current, next; /* First, set the new X coordinate of each profile */ current = *list; while ( current ) { current->X = *current->offset; current->offset += current->flags & Flow_Up ? 1 : -1; current->height--; current = current->link; } /* Then sort them */ old = list; current = *old; if ( !current ) return; next = current->link; while ( next ) { if ( current->X <= next->X ) { old = &current->link; current = *old; if ( !current ) return; } else { *old = next; current->link = next->link; next->link = current; old = list; current = *old; } next = current->link; } }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,592
Vertical_Sweep_Drop( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2, pxl; Short c1, f1; /* Drop-out control */ /* e2 x2 x1 e1 */ /* */ /* ^ | */ /* | | */ /* +-------------+---------------------+------------+ */ /* | | */ /* | v */ /* */ /* pixel contour contour pixel */ /* center center */ /* drop-out mode scan conversion rules (as defined in OpenType) */ /* --------------------------------------------------------------- */ /* 0 1, 2, 3 */ /* 1 1, 2, 4 */ /* 2 1, 2 */ /* 3 same as mode 2 */ /* 4 1, 2, 5 */ /* 5 1, 2, 6 */ /* 6, 7 same as mode 2 */ e1 = CEILING( x1 ); e2 = FLOOR ( x2 ); pxl = e1; if ( e1 > e2 ) { Int dropOutControl = left->flags & 7; if ( e1 == e2 + ras.precision ) { switch ( dropOutControl ) { case 0: /* simple drop-outs including stubs */ pxl = e2; break; case 4: /* smart drop-outs including stubs */ pxl = FLOOR( ( x1 + x2 - 1 ) / 2 + ras.precision_half ); break; case 1: /* simple drop-outs excluding stubs */ case 5: /* smart drop-outs excluding stubs */ /* Drop-out Control Rules #4 and #6 */ /* The specification neither provides an exact definition */ /* of a `stub' nor gives exact rules to exclude them. */ /* */ /* Here the constraints we use to recognize a stub. */ /* */ /* upper stub: */ /* */ /* - P_Left and P_Right are in the same contour */ /* - P_Right is the successor of P_Left in that contour */ /* - y is the top of P_Left and P_Right */ /* */ /* lower stub: */ /* */ /* - P_Left and P_Right are in the same contour */ /* - P_Left is the successor of P_Right in that contour */ /* - y is the bottom of P_Left */ /* */ /* We draw a stub if the following constraints are met. */ /* */ /* - for an upper or lower stub, there is top or bottom */ /* overshoot, respectively */ /* - the covered interval is greater or equal to a half */ /* pixel */ /* upper stub test */ if ( left->next == right && left->height <= 0 && !( left->flags & Overshoot_Top && x2 - x1 >= ras.precision_half ) ) return; /* lower stub test */ if ( right->next == left && left->start == y && !( left->flags & Overshoot_Bottom && x2 - x1 >= ras.precision_half ) ) return; if ( dropOutControl == 1 ) pxl = e2; else pxl = FLOOR( ( x1 + x2 - 1 ) / 2 + ras.precision_half ); break; default: /* modes 2, 3, 6, 7 */ return; /* no drop-out control */ } /* undocumented but confirmed: If the drop-out would result in a */ /* pixel outside of the bounding box, use the pixel inside of the */ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; else if ( TRUNC( pxl ) >= ras.bWidth ) pxl = e2; /* check that the other pixel isn't set */ e1 = pxl == e1 ? e2 : e1; e1 = TRUNC( e1 ); c1 = (Short)( e1 >> 3 ); f1 = (Short)( e1 & 7 ); if ( e1 >= 0 && e1 < ras.bWidth && ras.bTarget[ras.traceOfs + c1] & ( 0x80 >> f1 ) ) return; } else return; } e1 = TRUNC( pxl ); if ( e1 >= 0 && e1 < ras.bWidth ) { c1 = (Short)( e1 >> 3 ); f1 = (Short)( e1 & 7 ); if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1; if ( ras.gray_max_x < c1 ) ras.gray_max_x = c1; ras.bTarget[ras.traceOfs + c1] |= (char)( 0x80 >> f1 ); } }
DoS Overflow
0
Vertical_Sweep_Drop( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2, pxl; Short c1, f1; /* Drop-out control */ /* e2 x2 x1 e1 */ /* */ /* ^ | */ /* | | */ /* +-------------+---------------------+------------+ */ /* | | */ /* | v */ /* */ /* pixel contour contour pixel */ /* center center */ /* drop-out mode scan conversion rules (as defined in OpenType) */ /* --------------------------------------------------------------- */ /* 0 1, 2, 3 */ /* 1 1, 2, 4 */ /* 2 1, 2 */ /* 3 same as mode 2 */ /* 4 1, 2, 5 */ /* 5 1, 2, 6 */ /* 6, 7 same as mode 2 */ e1 = CEILING( x1 ); e2 = FLOOR ( x2 ); pxl = e1; if ( e1 > e2 ) { Int dropOutControl = left->flags & 7; if ( e1 == e2 + ras.precision ) { switch ( dropOutControl ) { case 0: /* simple drop-outs including stubs */ pxl = e2; break; case 4: /* smart drop-outs including stubs */ pxl = FLOOR( ( x1 + x2 - 1 ) / 2 + ras.precision_half ); break; case 1: /* simple drop-outs excluding stubs */ case 5: /* smart drop-outs excluding stubs */ /* Drop-out Control Rules #4 and #6 */ /* The specification neither provides an exact definition */ /* of a `stub' nor gives exact rules to exclude them. */ /* */ /* Here the constraints we use to recognize a stub. */ /* */ /* upper stub: */ /* */ /* - P_Left and P_Right are in the same contour */ /* - P_Right is the successor of P_Left in that contour */ /* - y is the top of P_Left and P_Right */ /* */ /* lower stub: */ /* */ /* - P_Left and P_Right are in the same contour */ /* - P_Left is the successor of P_Right in that contour */ /* - y is the bottom of P_Left */ /* */ /* We draw a stub if the following constraints are met. */ /* */ /* - for an upper or lower stub, there is top or bottom */ /* overshoot, respectively */ /* - the covered interval is greater or equal to a half */ /* pixel */ /* upper stub test */ if ( left->next == right && left->height <= 0 && !( left->flags & Overshoot_Top && x2 - x1 >= ras.precision_half ) ) return; /* lower stub test */ if ( right->next == left && left->start == y && !( left->flags & Overshoot_Bottom && x2 - x1 >= ras.precision_half ) ) return; if ( dropOutControl == 1 ) pxl = e2; else pxl = FLOOR( ( x1 + x2 - 1 ) / 2 + ras.precision_half ); break; default: /* modes 2, 3, 6, 7 */ return; /* no drop-out control */ } /* undocumented but confirmed: If the drop-out would result in a */ /* pixel outside of the bounding box, use the pixel inside of the */ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; else if ( TRUNC( pxl ) >= ras.bWidth ) pxl = e2; /* check that the other pixel isn't set */ e1 = pxl == e1 ? e2 : e1; e1 = TRUNC( e1 ); c1 = (Short)( e1 >> 3 ); f1 = (Short)( e1 & 7 ); if ( e1 >= 0 && e1 < ras.bWidth && ras.bTarget[ras.traceOfs + c1] & ( 0x80 >> f1 ) ) return; } else return; } e1 = TRUNC( pxl ); if ( e1 >= 0 && e1 < ras.bWidth ) { c1 = (Short)( e1 >> 3 ); f1 = (Short)( e1 & 7 ); if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1; if ( ras.gray_max_x < c1 ) ras.gray_max_x = c1; ras.bTarget[ras.traceOfs + c1] |= (char)( 0x80 >> f1 ); } }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,593
Vertical_Sweep_Init( RAS_ARGS Short* min, Short* max ) { Long pitch = ras.target.pitch; FT_UNUSED( max ); ras.traceIncr = (Short)-pitch; ras.traceOfs = -*min * pitch; if ( pitch > 0 ) ras.traceOfs += ( ras.target.rows - 1 ) * pitch; ras.gray_min_x = 0; ras.gray_max_x = 0; }
DoS Overflow
0
Vertical_Sweep_Init( RAS_ARGS Short* min, Short* max ) { Long pitch = ras.target.pitch; FT_UNUSED( max ); ras.traceIncr = (Short)-pitch; ras.traceOfs = -*min * pitch; if ( pitch > 0 ) ras.traceOfs += ( ras.target.rows - 1 ) * pitch; ras.gray_min_x = 0; ras.gray_max_x = 0; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,594
Vertical_Sweep_Span( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2; Byte* target; Int dropOutControl = left->flags & 7; FT_UNUSED( y ); FT_UNUSED( left ); FT_UNUSED( right ); /* Drop-out control */ e1 = TRUNC( CEILING( x1 ) ); if ( dropOutControl != 2 && x2 - x1 - ras.precision <= ras.precision_jitter ) e2 = e1; else e2 = TRUNC( FLOOR( x2 ) ); if ( e2 >= 0 && e1 < ras.bWidth ) { int c1, c2; Byte f1, f2; if ( e1 < 0 ) e1 = 0; if ( e2 >= ras.bWidth ) e2 = ras.bWidth - 1; c1 = (Short)( e1 >> 3 ); c2 = (Short)( e2 >> 3 ); f1 = (Byte) ( 0xFF >> ( e1 & 7 ) ); f2 = (Byte) ~( 0x7F >> ( e2 & 7 ) ); if ( ras.gray_min_x > c1 ) ras.gray_min_x = (short)c1; if ( ras.gray_max_x < c2 ) ras.gray_max_x = (short)c2; target = ras.bTarget + ras.traceOfs + c1; c2 -= c1; if ( c2 > 0 ) { target[0] |= f1; /* memset() is slower than the following code on many platforms. */ /* This is due to the fact that, in the vast majority of cases, */ /* the span length in bytes is relatively small. */ c2--; while ( c2 > 0 ) { *(++target) = 0xFF; c2--; } target[1] |= f2; } else *target |= ( f1 & f2 ); } }
DoS Overflow
0
Vertical_Sweep_Span( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2; Byte* target; Int dropOutControl = left->flags & 7; FT_UNUSED( y ); FT_UNUSED( left ); FT_UNUSED( right ); /* Drop-out control */ e1 = TRUNC( CEILING( x1 ) ); if ( dropOutControl != 2 && x2 - x1 - ras.precision <= ras.precision_jitter ) e2 = e1; else e2 = TRUNC( FLOOR( x2 ) ); if ( e2 >= 0 && e1 < ras.bWidth ) { int c1, c2; Byte f1, f2; if ( e1 < 0 ) e1 = 0; if ( e2 >= ras.bWidth ) e2 = ras.bWidth - 1; c1 = (Short)( e1 >> 3 ); c2 = (Short)( e2 >> 3 ); f1 = (Byte) ( 0xFF >> ( e1 & 7 ) ); f2 = (Byte) ~( 0x7F >> ( e2 & 7 ) ); if ( ras.gray_min_x > c1 ) ras.gray_min_x = (short)c1; if ( ras.gray_max_x < c2 ) ras.gray_max_x = (short)c2; target = ras.bTarget + ras.traceOfs + c1; c2 -= c1; if ( c2 > 0 ) { target[0] |= f1; /* memset() is slower than the following code on many platforms. */ /* This is due to the fact that, in the vast majority of cases, */ /* the span length in bytes is relatively small. */ c2--; while ( c2 > 0 ) { *(++target) = 0xFF; c2--; } target[1] |= f2; } else *target |= ( f1 & f2 ); } }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,595
ft_black_done( FT_Raster raster ) { /* nothing */ FT_UNUSED( raster ); }
DoS Overflow
0
ft_black_done( FT_Raster raster ) { /* nothing */ FT_UNUSED( raster ); }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,596
ft_black_done( black_PRaster raster ) { FT_Memory memory = (FT_Memory)raster->memory; FT_FREE( raster ); }
DoS Overflow
0
ft_black_done( black_PRaster raster ) { FT_Memory memory = (FT_Memory)raster->memory; FT_FREE( raster ); }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,597
ft_black_init( black_PRaster raster ) { #ifdef FT_RASTER_OPTION_ANTI_ALIASING FT_UInt n; /* set default 5-levels gray palette */ for ( n = 0; n < 5; n++ ) raster->grays[n] = n * 255 / 4; raster->gray_width = RASTER_GRAY_LINES / 2; #else FT_UNUSED( raster ); #endif }
DoS Overflow
0
ft_black_init( black_PRaster raster ) { #ifdef FT_RASTER_OPTION_ANTI_ALIASING FT_UInt n; /* set default 5-levels gray palette */ for ( n = 0; n < 5; n++ ) raster->grays[n] = n * 255 / 4; raster->gray_width = RASTER_GRAY_LINES / 2; #else FT_UNUSED( raster ); #endif }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,598
ft_black_new( void* memory, FT_Raster *araster ) { static black_TRaster the_raster; FT_UNUSED( memory ); *araster = (FT_Raster)&the_raster; FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) ); ft_black_init( &the_raster ); return 0; }
DoS Overflow
0
ft_black_new( void* memory, FT_Raster *araster ) { static black_TRaster the_raster; FT_UNUSED( memory ); *araster = (FT_Raster)&the_raster; FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) ); ft_black_init( &the_raster ); return 0; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null
5,599
ft_black_new( FT_Memory memory, black_PRaster *araster ) { FT_Error error; black_PRaster raster = NULL; *araster = 0; if ( !FT_NEW( raster ) ) { raster->memory = memory; ft_black_init( raster ); *araster = raster; } return error; }
DoS Overflow
0
ft_black_new( FT_Memory memory, black_PRaster *araster ) { FT_Error error; black_PRaster raster = NULL; *araster = 0; if ( !FT_NEW( raster ) ) { raster->memory = memory; ft_black_init( raster ); *araster = raster; } return error; }
@@ -2553,7 +2553,7 @@ e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; @@ -2647,7 +2647,7 @@ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; - else if ( TRUNC( pxl ) >= ras.target.rows ) + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ @@ -2662,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2676,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 )
CWE-119
null
null