func
stringlengths 12
2.67k
| cwe
stringclasses 7
values | __index_level_0__
int64 0
20k
|
|---|---|---|
TPM2B_MAX_BUFFER_Marshal(TPM2B_MAX_BUFFER *source, BYTE **buffer, INT32 *size)
{
UINT16 written = 0;
written += TPM2B_Marshal(&source->b, buffer, size);
return written;
}
|
CWE-787
| 17,577
|
TPM2B_DATA_Marshal(TPM2B_DATA *source, BYTE **buffer, INT32 *size)
{
UINT16 written = 0;
written += TPM2B_Marshal(&source->b, buffer, size);
return written;
}
|
CWE-787
| 17,578
|
TPM2B_NAME_Marshal(TPM2B_NAME *source, BYTE **buffer, INT32 *size)
{
UINT16 written = 0;
written += TPM2B_Marshal(&source->b, buffer, size);
return written;
}
|
CWE-787
| 17,579
|
TPM2B_PUBLIC_KEY_RSA_Marshal(TPM2B_PUBLIC_KEY_RSA *source, BYTE **buffer, INT32 *size)
{
UINT16 written = 0;
written += TPM2B_Marshal(&source->b, buffer, size);
return written;
}
|
CWE-787
| 17,580
|
static int http_buf_read(URLContext *h, uint8_t *buf, int size)
{
HTTPContext *s = h->priv_data;
int len;
/* read bytes from input buffer first */
len = s->buf_end - s->buf_ptr;
if (len > 0) {
if (len > size)
len = size;
memcpy(buf, s->buf_ptr, len);
s->buf_ptr += len;
} else {
int64_t target_end = s->end_off ? s->end_off : s->filesize;
if ((!s->willclose || s->chunksize < 0) &&
target_end >= 0 && s->off >= target_end)
return AVERROR_EOF;
len = ffurl_read(s->hd, buf, size);
if (!len && (!s->willclose || s->chunksize < 0) &&
target_end >= 0 && s->off < target_end) {
av_log(h, AV_LOG_ERROR,
"Stream ends prematurely at %"PRId64", should be %"PRId64"\n",
s->off, target_end
);
return AVERROR(EIO);
}
}
if (len > 0) {
s->off += len;
if (s->chunksize > 0)
s->chunksize -= len;
}
return len;
}
|
CWE-119
| 17,586
|
static int store_icy(URLContext *h, int size)
{
HTTPContext *s = h->priv_data;
/* until next metadata packet */
int remaining = s->icy_metaint - s->icy_data_read;
if (remaining < 0)
return AVERROR_INVALIDDATA;
if (!remaining) {
/* The metadata packet is variable sized. It has a 1 byte header
* which sets the length of the packet (divided by 16). If it's 0,
* the metadata doesn't change. After the packet, icy_metaint bytes
* of normal data follows. */
uint8_t ch;
int len = http_read_stream_all(h, &ch, 1);
if (len < 0)
return len;
if (ch > 0) {
char data[255 * 16 + 1];
int ret;
len = ch * 16;
ret = http_read_stream_all(h, data, len);
if (ret < 0)
return ret;
data[len + 1] = 0;
if ((ret = av_opt_set(s, "icy_metadata_packet", data, 0)) < 0)
return ret;
update_metadata(s, data);
}
s->icy_data_read = 0;
remaining = s->icy_metaint;
}
return FFMIN(size, remaining);
}
|
CWE-119
| 17,588
|
static void parse_content_range(URLContext *h, const char *p)
{
HTTPContext *s = h->priv_data;
const char *slash;
if (!strncmp(p, "bytes ", 6)) {
p += 6;
s->off = strtoll(p, NULL, 10);
if ((slash = strchr(p, '/')) && strlen(slash) > 0)
s->filesize = strtoll(slash + 1, NULL, 10);
}
if (s->seekable == -1 && (!s->is_akamai || s->filesize != 2147483647))
h->is_streamed = 0; /* we _can_ in fact seek */
}
|
CWE-119
| 17,589
|
static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int force_reconnect)
{
HTTPContext *s = h->priv_data;
URLContext *old_hd = s->hd;
int64_t old_off = s->off;
uint8_t old_buf[BUFFER_SIZE];
int old_buf_size, ret;
AVDictionary *options = NULL;
if (whence == AVSEEK_SIZE)
return s->filesize;
else if (!force_reconnect &&
((whence == SEEK_CUR && off == 0) ||
(whence == SEEK_SET && off == s->off)))
return s->off;
else if ((s->filesize == -1 && whence == SEEK_END))
return AVERROR(ENOSYS);
if (whence == SEEK_CUR)
off += s->off;
else if (whence == SEEK_END)
off += s->filesize;
else if (whence != SEEK_SET)
return AVERROR(EINVAL);
if (off < 0)
return AVERROR(EINVAL);
s->off = off;
if (s->off && h->is_streamed)
return AVERROR(ENOSYS);
/* we save the old context in case the seek fails */
old_buf_size = s->buf_end - s->buf_ptr;
memcpy(old_buf, s->buf_ptr, old_buf_size);
s->hd = NULL;
/* if it fails, continue on old connection */
if ((ret = http_open_cnx(h, &options)) < 0) {
av_dict_free(&options);
memcpy(s->buffer, old_buf, old_buf_size);
s->buf_ptr = s->buffer;
s->buf_end = s->buffer + old_buf_size;
s->hd = old_hd;
s->off = old_off;
return ret;
}
av_dict_free(&options);
ffurl_close(old_hd);
return off;
}
|
CWE-119
| 17,590
|
static int http_open(URLContext *h, const char *uri, int flags,
AVDictionary **options)
{
HTTPContext *s = h->priv_data;
int ret;
if( s->seekable == 1 )
h->is_streamed = 0;
else
h->is_streamed = 1;
s->filesize = -1;
s->location = av_strdup(uri);
if (!s->location)
return AVERROR(ENOMEM);
if (options)
av_dict_copy(&s->chained_options, *options, 0);
if (s->headers) {
int len = strlen(s->headers);
if (len < 2 || strcmp("\r\n", s->headers + len - 2)) {
av_log(h, AV_LOG_WARNING,
"No trailing CRLF found in HTTP header.\n");
ret = av_reallocp(&s->headers, len + 3);
if (ret < 0)
return ret;
s->headers[len] = '\r';
s->headers[len + 1] = '\n';
s->headers[len + 2] = '\0';
}
}
if (s->listen) {
return http_listen(h, uri, flags, options);
}
ret = http_open_cnx(h, options);
if (ret < 0)
av_dict_free(&s->chained_options);
return ret;
}
|
CWE-119
| 17,591
|
static int http_read_header(URLContext *h, int *new_location)
{
HTTPContext *s = h->priv_data;
char line[MAX_URL_SIZE];
int err = 0;
s->chunksize = -1;
for (;;) {
if ((err = http_get_line(s, line, sizeof(line))) < 0)
return err;
av_log(h, AV_LOG_TRACE, "header='%s'\n", line);
err = process_line(h, line, s->line_count, new_location);
if (err < 0)
return err;
if (err == 0)
break;
s->line_count++;
}
if (s->seekable == -1 && s->is_mediagateway && s->filesize == 2000000000)
h->is_streamed = 1; /* we can in fact _not_ seek */
// add any new cookies into the existing cookie string
cookie_string(s->cookie_dict, &s->cookies);
av_dict_free(&s->cookie_dict);
return err;
}
|
CWE-119
| 17,593
|
void mlock_vma_page(struct page *page)
{
BUG_ON(!PageLocked(page));
if (!TestSetPageMlocked(page)) {
mod_zone_page_state(page_zone(page), NR_MLOCK,
hpage_nr_pages(page));
count_vm_event(UNEVICTABLE_PGMLOCKED);
if (!isolate_lru_page(page))
putback_lru_page(page);
}
}
|
CWE-703
| 17,595
|
unsigned int munlock_vma_page(struct page *page)
{
unsigned int nr_pages;
struct zone *zone = page_zone(page);
BUG_ON(!PageLocked(page));
/*
* Serialize with any parallel __split_huge_page_refcount() which
* might otherwise copy PageMlocked to part of the tail pages before
* we clear it in the head page. It also stabilizes hpage_nr_pages().
*/
spin_lock_irq(&zone->lru_lock);
nr_pages = hpage_nr_pages(page);
if (!TestClearPageMlocked(page))
goto unlock_out;
__mod_zone_page_state(zone, NR_MLOCK, -nr_pages);
if (__munlock_isolate_lru_page(page, true)) {
spin_unlock_irq(&zone->lru_lock);
__munlock_isolated_page(page);
goto out;
}
__munlock_isolation_failed(page);
unlock_out:
spin_unlock_irq(&zone->lru_lock);
out:
return nr_pages - 1;
}
|
CWE-703
| 17,596
|
static Status Compute(OpKernelContext* context,
const typename TTypes<T, 1>::ConstTensor& values,
const typename TTypes<T, 1>::ConstTensor& value_range,
int32_t nbins, typename TTypes<Tout, 1>::Tensor& out) {
const CPUDevice& d = context->eigen_device<CPUDevice>();
Tensor index_to_bin_tensor;
TF_RETURN_IF_ERROR(context->forward_input_or_allocate_temp(
{0}, DataTypeToEnum<int32>::value, TensorShape({values.size()}),
&index_to_bin_tensor));
auto index_to_bin = index_to_bin_tensor.flat<int32>();
const double step = static_cast<double>(value_range(1) - value_range(0)) /
static_cast<double>(nbins);
const double nbins_minus_1 = static_cast<double>(nbins - 1);
// The calculation is done by finding the slot of each value in `values`.
// With [a, b]:
// step = (b - a) / nbins
// (x - a) / step
// , then the entries are mapped to output.
// Bug fix: Switch the order of cwiseMin and int32-casting to avoid
// producing a negative index when casting an big int64 number to int32
index_to_bin.device(d) =
((values.cwiseMax(value_range(0)) - values.constant(value_range(0)))
.template cast<double>() /
step)
.cwiseMin(nbins_minus_1)
.template cast<int32>();
out.setZero();
for (int32_t i = 0; i < index_to_bin.size(); i++) {
out(index_to_bin(i)) += Tout(1);
}
return Status::OK();
}
|
CWE-20
| 17,601
|
void Compute(OpKernelContext* ctx) override {
const Tensor& values_tensor = ctx->input(0);
const Tensor& value_range_tensor = ctx->input(1);
const Tensor& nbins_tensor = ctx->input(2);
OP_REQUIRES(ctx, TensorShapeUtils::IsVector(value_range_tensor.shape()),
errors::InvalidArgument("value_range should be a vector."));
OP_REQUIRES(ctx, (value_range_tensor.shape().num_elements() == 2),
errors::InvalidArgument(
"value_range should be a vector of 2 elements."));
OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(nbins_tensor.shape()),
errors::InvalidArgument("nbins should be a scalar."));
const auto values = values_tensor.flat<T>();
const auto value_range = value_range_tensor.flat<T>();
const auto nbins = nbins_tensor.scalar<int32>()();
OP_REQUIRES(
ctx, (value_range(0) < value_range(1)),
errors::InvalidArgument("value_range should satisfy value_range[0] < "
"value_range[1], but got '[",
value_range(0), ", ", value_range(1), "]'"));
OP_REQUIRES(
ctx, (nbins > 0),
errors::InvalidArgument("nbins should be a positive number, but got '",
nbins, "'"));
Tensor* out_tensor;
OP_REQUIRES_OK(ctx,
ctx->allocate_output(0, TensorShape({nbins}), &out_tensor));
auto out = out_tensor->flat<Tout>();
OP_REQUIRES_OK(
ctx, functor::HistogramFixedWidthFunctor<Device, T, Tout>::Compute(
ctx, values, value_range, nbins, out));
}
|
CWE-20
| 17,602
|
rsvg_handle_write_impl (RsvgHandle * handle, const guchar * buf, gsize count, GError ** error)
{
GError *real_error = NULL;
int result;
rsvg_return_val_if_fail (handle != NULL, FALSE, error);
handle->priv->error = &real_error;
if (handle->priv->ctxt == NULL) {
handle->priv->ctxt = xmlCreatePushParserCtxt (&rsvgSAXHandlerStruct, handle, NULL, 0,
rsvg_handle_get_base_uri (handle));
/* if false, external entities work, but internal ones don't. if true, internal entities
work, but external ones don't. favor internal entities, in order to not cause a
regression */
handle->priv->ctxt->replaceEntities = TRUE;
}
result = xmlParseChunk (handle->priv->ctxt, (char *) buf, count, 0);
if (result != 0) {
rsvg_set_error (error, handle->priv->ctxt);
return FALSE;
}
handle->priv->error = NULL;
if (real_error != NULL) {
g_propagate_error (error, real_error);
return FALSE;
}
return TRUE;
}
|
CWE-20
| 17,794
|
rsvg_css_parse_xml_attribute_string (const char *attribute_string)
{
xmlSAXHandler handler;
xmlParserCtxtPtr parser;
xmlDocPtr doc;
xmlNodePtr node;
xmlAttrPtr attr;
char *tag;
GPtrArray *attributes;
char **retval = NULL;
tag = g_strdup_printf ("<rsvg-hack %s />\n", attribute_string);
memset (&handler, 0, sizeof (handler));
xmlSAX2InitDefaultSAXHandler (&handler, 0);
handler.serror = rsvg_xml_noerror;
parser = xmlCreatePushParserCtxt (&handler, NULL, tag, strlen (tag) + 1, NULL);
if (xmlParseDocument (parser) != 0)
goto done;
if ((doc = parser->myDoc) == NULL ||
(node = doc->children) == NULL ||
strcmp (node->name, "rsvg-hack") != 0 ||
node->next != NULL ||
node->properties == NULL)
goto done;
attributes = g_ptr_array_new ();
for (attr = node->properties; attr; attr = attr->next) {
xmlNodePtr content = attr->children;
g_ptr_array_add (attributes, g_strdup ((char *) attr->name));
if (content)
g_ptr_array_add (attributes, g_strdup ((char *) content->content));
else
g_ptr_array_add (attributes, g_strdup (""));
}
g_ptr_array_add (attributes, NULL);
retval = (char **) g_ptr_array_free (attributes, FALSE);
done:
if (parser->myDoc)
xmlFreeDoc (parser->myDoc);
xmlFreeParserCtxt (parser);
g_free (tag);
return retval;
}
|
CWE-20
| 17,795
|
rsvg_acquire_data_data (const char *uri,
const char *base_uri,
char **out_mime_type,
gsize *out_len,
GError **error)
{
const char *comma, *start, *end;
char *mime_type;
char *data;
gsize data_len;
gboolean base64 = FALSE;
g_assert (out_len != NULL);
g_assert (g_str_has_prefix (uri, "data:"));
mime_type = NULL;
start = uri + 5;
comma = strchr (start, ',');
if (comma && comma != start) {
/* Deal with MIME type / params */
if (comma > start + BASE64_INDICATOR_LEN &&
!g_ascii_strncasecmp (comma - BASE64_INDICATOR_LEN, BASE64_INDICATOR, BASE64_INDICATOR_LEN)) {
end = comma - BASE64_INDICATOR_LEN;
base64 = TRUE;
} else {
end = comma;
}
if (end != start) {
mime_type = uri_decoded_copy (start, end - start);
}
}
if (comma)
start = comma + 1;
if (*start) {
data = uri_decoded_copy (start, strlen (start));
if (base64)
data = g_base64_decode_inplace ((char*) data, &data_len);
else
data_len = strlen ((const char *) data);
} else {
data = NULL;
data_len = 0;
}
if (out_mime_type)
*out_mime_type = mime_type;
else
g_free (mime_type);
*out_len = data_len;
return data;
}
|
CWE-20
| 17,796
|
rsvg_handle_set_base_uri (RsvgHandle * handle, const char *base_uri)
{
gchar *uri;
g_return_if_fail (handle != NULL);
if (base_uri == NULL)
return;
if (rsvg_path_is_uri (base_uri))
uri = g_strdup (base_uri);
else
uri = rsvg_get_base_uri_from_filename (base_uri);
if (uri) {
if (handle->priv->base_uri)
g_free (handle->priv->base_uri);
handle->priv->base_uri = uri;
}
}
|
CWE-20
| 17,797
|
_rsvg_handle_allow_load (RsvgHandle *handle,
const char *uri,
GError **error)
{
RsvgLoadPolicy policy = handle->priv->load_policy;
if (policy == RSVG_LOAD_POLICY_ALL_PERMISSIVE)
return TRUE;
return TRUE;
}
|
CWE-20
| 17,798
|
static void ssl3_take_mac(SSL *s)
{
const char *sender;
int slen;
if (s->state & SSL_ST_CONNECT)
{
sender=s->method->ssl3_enc->server_finished_label;
slen=s->method->ssl3_enc->server_finished_label_len;
}
else
{
sender=s->method->ssl3_enc->client_finished_label;
slen=s->method->ssl3_enc->client_finished_label_len;
}
s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
sender,slen,s->s3->tmp.peer_finish_md);
}
|
CWE-20
| 17,822
|
static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g)
{
/* k = SHA1(N | PAD(g)) -- tls-srp draft 8 */
unsigned char digest[SHA_DIGEST_LENGTH];
unsigned char *tmp;
EVP_MD_CTX ctxt;
int longg ;
int longN = BN_num_bytes(N);
if ((tmp = OPENSSL_malloc(longN)) == NULL)
return NULL;
BN_bn2bin(N,tmp) ;
EVP_MD_CTX_init(&ctxt);
EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
EVP_DigestUpdate(&ctxt, tmp, longN);
memset(tmp, 0, longN);
longg = BN_bn2bin(g,tmp) ;
/* use the zeros behind to pad on left */
EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg);
EVP_DigestUpdate(&ctxt, tmp, longg);
OPENSSL_free(tmp);
EVP_DigestFinal_ex(&ctxt, digest, NULL);
EVP_MD_CTX_cleanup(&ctxt);
return BN_bin2bn(digest, sizeof(digest), NULL);
}
|
CWE-119
| 17,958
|
BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N)
{
/* k = SHA1(PAD(A) || PAD(B) ) -- tls-srp draft 8 */
BIGNUM *u;
unsigned char cu[SHA_DIGEST_LENGTH];
unsigned char *cAB;
EVP_MD_CTX ctxt;
int longN;
if ((A == NULL) ||(B == NULL) || (N == NULL))
return NULL;
longN= BN_num_bytes(N);
if ((cAB = OPENSSL_malloc(2*longN)) == NULL)
return NULL;
memset(cAB, 0, longN);
EVP_MD_CTX_init(&ctxt);
EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(A,cAB+longN), longN);
EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(B,cAB+longN), longN);
OPENSSL_free(cAB);
EVP_DigestFinal_ex(&ctxt, cu, NULL);
EVP_MD_CTX_cleanup(&ctxt);
if (!(u = BN_bin2bn(cu, sizeof(cu), NULL)))
return NULL;
if (!BN_is_zero(u))
return u;
BN_free(u);
return NULL;
}
|
CWE-119
| 17,959
|
static int find_profile_by_num(unsigned profile_num,
SRTP_PROTECTION_PROFILE **pptr)
{
SRTP_PROTECTION_PROFILE *p;
p=srtp_known_profiles;
while(p->name)
{
if(p->id == profile_num)
{
*pptr=p;
return 0;
}
p++;
}
return 1;
}
|
CWE-20
| 18,000
|
static int ssl_ctx_make_profiles(const char *profiles_string,STACK_OF(SRTP_PROTECTION_PROFILE) **out)
{
STACK_OF(SRTP_PROTECTION_PROFILE) *profiles;
char *col;
char *ptr=(char *)profiles_string;
SRTP_PROTECTION_PROFILE *p;
if(!(profiles=sk_SRTP_PROTECTION_PROFILE_new_null()))
{
SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES, SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
return 1;
}
do
{
col=strchr(ptr,':');
if(!find_profile_by_name(ptr,&p,
col ? col-ptr : (int)strlen(ptr)))
{
sk_SRTP_PROTECTION_PROFILE_push(profiles,p);
}
else
{
SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);
return 1;
}
if(col) ptr=col+1;
} while (col);
*out=profiles;
return 0;
}
|
CWE-20
| 18,001
|
_rsvg_node_poly_build_path (const char *value,
gboolean close_path)
{
double *pointlist;
guint pointlist_len, i;
GString *d;
cairo_path_t *path;
char buf[G_ASCII_DTOSTR_BUF_SIZE];
pointlist = rsvg_css_parse_number_list (value, &pointlist_len);
if (pointlist == NULL)
return NULL;
if (pointlist_len < 2) {
g_free (pointlist);
return NULL;
}
d = g_string_new (NULL);
/* "M %f %f " */
g_string_append (d, " M ");
g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), pointlist[0]));
g_string_append_c (d, ' ');
g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), pointlist[1]));
/* "L %f %f " */
for (i = 2; i < pointlist_len; i += 2) {
g_string_append (d, " L ");
g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), pointlist[i]));
g_string_append_c (d, ' ');
g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), pointlist[i + 1]));
}
if (close_path)
g_string_append (d, " Z");
path = rsvg_parse_path (d->str);
g_string_free (d, TRUE);
g_free (pointlist);
return path;
}
|
CWE-20
| 18,013
|
dtls1_process_buffered_records(SSL *s)
{
pitem *item;
item = pqueue_peek(s->d1->unprocessed_rcds.q);
if (item)
{
/* Check if epoch is current. */
if (s->d1->unprocessed_rcds.epoch != s->d1->r_epoch)
return(1); /* Nothing to do. */
/* Process all the records. */
while (pqueue_peek(s->d1->unprocessed_rcds.q))
{
dtls1_get_unprocessed_record(s);
if ( ! dtls1_process_record(s))
return(0);
dtls1_buffer_record(s, &(s->d1->processed_rcds),
s->s3->rrec.seq_num);
}
}
/* sync epoch numbers once all the unprocessed records
* have been processed */
s->d1->processed_rcds.epoch = s->d1->r_epoch;
s->d1->unprocessed_rcds.epoch = s->d1->r_epoch + 1;
return(1);
}
|
CWE-119
| 18,054
|
DECLAREContigPutFunc(putcontig8bitYCbCr21tile)
{
(void) y;
fromskew = (fromskew * 4) / 2;
do {
x = w>>1;
do {
int32 Cb = pp[2];
int32 Cr = pp[3];
YCbCrtoRGB(cp[0], pp[0]);
YCbCrtoRGB(cp[1], pp[1]);
cp += 2;
pp += 4;
} while (--x);
if( (w&1) != 0 )
{
int32 Cb = pp[2];
int32 Cr = pp[3];
YCbCrtoRGB(cp[0], pp[0]);
cp += 1;
pp += 4;
}
cp += toskew;
pp += fromskew;
} while (--h);
}
|
CWE-119
| 18,074
|
DECLAREContigPutFunc(putcontig8bitYCbCr41tile)
{
(void) y;
/* XXX adjust fromskew */
do {
x = w>>2;
do {
int32 Cb = pp[4];
int32 Cr = pp[5];
YCbCrtoRGB(cp [0], pp[0]);
YCbCrtoRGB(cp [1], pp[1]);
YCbCrtoRGB(cp [2], pp[2]);
YCbCrtoRGB(cp [3], pp[3]);
cp += 4;
pp += 6;
} while (--x);
if( (w&3) != 0 )
{
int32 Cb = pp[4];
int32 Cr = pp[5];
switch( (w&3) ) {
case 3: YCbCrtoRGB(cp [2], pp[2]);
case 2: YCbCrtoRGB(cp [1], pp[1]);
case 1: YCbCrtoRGB(cp [0], pp[0]);
case 0: break;
}
cp += (w&3);
pp += 6;
}
cp += toskew;
pp += fromskew;
} while (--h);
}
|
CWE-119
| 18,076
|
LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
LogLuvState* sp = EncoderState(tif);
tmsize_t i;
tmsize_t npixels;
tmsize_t occ;
uint8* op;
uint32* tp;
assert(s == 0);
assert(sp != NULL);
npixels = cc / sp->pixel_size;
if (sp->user_datafmt == SGILOGDATAFMT_RAW)
tp = (uint32*) bp;
else {
tp = (uint32*) sp->tbuf;
assert(sp->tbuflen >= npixels);
(*sp->tfunc)(sp, bp, npixels);
}
/* write out encoded pixels */
op = tif->tif_rawcp;
occ = tif->tif_rawdatasize - tif->tif_rawcc;
for (i = npixels; i--; ) {
if (occ < 3) {
tif->tif_rawcp = op;
tif->tif_rawcc = tif->tif_rawdatasize - occ;
if (!TIFFFlushData1(tif))
return (-1);
op = tif->tif_rawcp;
occ = tif->tif_rawdatasize - tif->tif_rawcc;
}
*op++ = (uint8)(*tp >> 16);
*op++ = (uint8)(*tp >> 8 & 0xff);
*op++ = (uint8)(*tp++ & 0xff);
occ -= 3;
}
tif->tif_rawcp = op;
tif->tif_rawcc = tif->tif_rawdatasize - occ;
return (1);
}
|
CWE-787
| 18,179
|
LogLuvDecode24(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
{
static const char module[] = "LogLuvDecode24";
LogLuvState* sp = DecoderState(tif);
tmsize_t cc;
tmsize_t i;
tmsize_t npixels;
unsigned char* bp;
uint32* tp;
assert(s == 0);
assert(sp != NULL);
npixels = occ / sp->pixel_size;
if (sp->user_datafmt == SGILOGDATAFMT_RAW)
tp = (uint32 *)op;
else {
assert(sp->tbuflen >= npixels);
tp = (uint32 *) sp->tbuf;
}
/* copy to array of uint32 */
bp = (unsigned char*) tif->tif_rawcp;
cc = tif->tif_rawcc;
for (i = 0; i < npixels && cc > 0; i++) {
tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2];
bp += 3;
cc -= 3;
}
tif->tif_rawcp = (uint8*) bp;
tif->tif_rawcc = cc;
if (i != npixels) {
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
TIFFErrorExt(tif->tif_clientdata, module,
"Not enough data at row %lu (short %I64d pixels)",
(unsigned long) tif->tif_row,
(unsigned __int64) (npixels - i));
#else
TIFFErrorExt(tif->tif_clientdata, module,
"Not enough data at row %lu (short %llu pixels)",
(unsigned long) tif->tif_row,
(unsigned long long) (npixels - i));
#endif
return (0);
}
(*sp->tfunc)(sp, op, npixels);
return (1);
}
|
CWE-787
| 18,180
|
fmtstr(char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen, const char *value, int flags, int min, int max)
{
int padlen, strln;
int cnt = 0;
if (value == 0)
value = "<NULL>";
for (strln = 0; value[strln]; ++strln) ;
padlen = min - strln;
if (padlen < 0)
padlen = 0;
if (flags & DP_F_MINUS)
padlen = -padlen;
while ((padlen > 0) && (cnt < max)) {
doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
--padlen;
++cnt;
}
while (*value && (cnt < max)) {
doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
++cnt;
}
while ((padlen < 0) && (cnt < max)) {
doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
++padlen;
++cnt;
}
}
|
CWE-119
| 18,210
|
int BIO_vprintf(BIO *bio, const char *format, va_list args)
{
int ret;
size_t retlen;
char hugebuf[1024 * 2]; /* Was previously 10k, which is unreasonable
* in small-stack environments, like threads
* or DOS programs. */
char *hugebufp = hugebuf;
size_t hugebufsize = sizeof(hugebuf);
char *dynbuf = NULL;
int ignored;
dynbuf = NULL;
_dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, format, args);
if (dynbuf) {
ret = BIO_write(bio, dynbuf, (int)retlen);
OPENSSL_free(dynbuf);
} else {
ret = BIO_write(bio, hugebuf, (int)retlen);
}
return (ret);
}
|
CWE-119
| 18,211
|
doapr_outch(char **sbuffer,
char **buffer, size_t *currlen, size_t *maxlen, int c)
{
/* If we haven't at least one buffer, someone has doe a big booboo */
assert(*sbuffer != NULL || buffer != NULL);
/* |currlen| must always be <= |*maxlen| */
assert(*currlen <= *maxlen);
if (buffer && *currlen == *maxlen) {
*maxlen += 1024;
if (*buffer == NULL) {
*buffer = OPENSSL_malloc(*maxlen);
if (*buffer == NULL) {
/* Panic! Can't really do anything sensible. Just return */
return;
}
if (*currlen > 0) {
assert(*sbuffer != NULL);
memcpy(*buffer, *sbuffer, *currlen);
}
*sbuffer = NULL;
} else {
*buffer = OPENSSL_realloc(*buffer, *maxlen);
if (!*buffer) {
/* Panic! Can't really do anything sensible. Just return */
return;
}
}
}
if (*currlen < *maxlen) {
if (*sbuffer)
(*sbuffer)[(*currlen)++] = (char)c;
else
(*buffer)[(*currlen)++] = (char)c;
}
return;
}
|
CWE-119
| 18,213
|
int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
{
size_t retlen;
int truncated;
_dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
if (truncated)
/*
* In case of truncation, return -1 like traditional snprintf.
* (Current drafts for ISO/IEC 9899 say snprintf should return the
* number of characters that would have been written, had the buffer
* been large enough.)
*/
return -1;
else
return (retlen <= INT_MAX) ? (int)retlen : -1;
}
|
CWE-119
| 18,214
|
doapr_outch(char **sbuffer,
char **buffer, size_t *currlen, size_t *maxlen, int c)
{
/* If we haven't at least one buffer, someone has doe a big booboo */
assert(*sbuffer != NULL || buffer != NULL);
/* |currlen| must always be <= |*maxlen| */
assert(*currlen <= *maxlen);
if (buffer && *currlen == *maxlen) {
*maxlen += 1024;
if (*buffer == NULL) {
*buffer = OPENSSL_malloc(*maxlen);
if (!*buffer) {
/* Panic! Can't really do anything sensible. Just return */
return;
}
if (*currlen > 0) {
assert(*sbuffer != NULL);
memcpy(*buffer, *sbuffer, *currlen);
}
*sbuffer = NULL;
} else {
*buffer = OPENSSL_realloc(*buffer, *maxlen);
if (!*buffer) {
/* Panic! Can't really do anything sensible. Just return */
return;
}
}
}
if (*currlen < *maxlen) {
if (*sbuffer)
(*sbuffer)[(*currlen)++] = (char)c;
else
(*buffer)[(*currlen)++] = (char)c;
}
return;
}
|
CWE-119
| 18,217
|
int BIO_vprintf(BIO *bio, const char *format, va_list args)
{
int ret;
size_t retlen;
char hugebuf[1024 * 2]; /* Was previously 10k, which is unreasonable
* in small-stack environments, like threads
* or DOS programs. */
char *hugebufp = hugebuf;
size_t hugebufsize = sizeof(hugebuf);
char *dynbuf = NULL;
int ignored;
dynbuf = NULL;
CRYPTO_push_info("doapr()");
_dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, format, args);
if (dynbuf) {
ret = BIO_write(bio, dynbuf, (int)retlen);
OPENSSL_free(dynbuf);
} else {
ret = BIO_write(bio, hugebuf, (int)retlen);
}
CRYPTO_pop_info();
return (ret);
}
|
CWE-119
| 18,218
|
int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
{
int pad = 0, ret, i, neg;
unsigned char *p, *n, pb = 0;
if (a == NULL)
return (0);
neg = a->type & V_ASN1_NEG;
if (a->length == 0)
ret = 1;
else {
ret = a->length;
i = a->data[0];
if (!neg && (i > 127)) {
pad = 1;
pb = 0;
} else if (neg) {
if (i > 128) {
pad = 1;
pb = 0xFF;
} else if (i == 128) {
/*
* Special case: if any other bytes non zero we pad:
* otherwise we don't.
*/
for (i = 1; i < a->length; i++)
if (a->data[i]) {
pad = 1;
pb = 0xFF;
break;
}
}
}
ret += pad;
}
if (pp == NULL)
return (ret);
p = *pp;
if (pad)
*(p++) = pb;
if (a->length == 0)
*(p++) = 0;
else if (!neg)
memcpy(p, a->data, (unsigned int)a->length);
else {
/* Begin at the end of the encoding */
n = a->data + a->length - 1;
p += a->length - 1;
i = a->length;
/* Copy zeros to destination as long as source is zero */
while (!*n) {
*(p--) = 0;
n--;
i--;
}
/* Complement and increment next octet */
*(p--) = ((*(n--)) ^ 0xff) + 1;
i--;
/* Complement any octets left */
for (; i > 0; i--)
*(p--) = *(n--) ^ 0xff;
}
*pp += ret;
return (ret);
}
|
CWE-119
| 18,221
|
ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
{
ASN1_INTEGER *ret;
int len, j;
if (ai == NULL)
ret = M_ASN1_INTEGER_new();
else
ret = ai;
if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (BN_is_negative(bn))
ret->type = V_ASN1_NEG_INTEGER;
else
ret->type = V_ASN1_INTEGER;
j = BN_num_bits(bn);
len = ((j == 0) ? 0 : ((j / 8) + 1));
if (ret->length < len + 4) {
unsigned char *new_data = OPENSSL_realloc(ret->data, len + 4);
if (!new_data) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
goto err;
}
ret->data = new_data;
}
ret->length = BN_bn2bin(bn, ret->data);
/* Correct zero case */
if (!ret->length) {
ret->data[0] = 0;
ret->length = 1;
}
return (ret);
err:
if (ret != ai)
M_ASN1_INTEGER_free(ret);
return (NULL);
}
|
CWE-119
| 18,222
|
int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
{
int result = -1;
if (!a || !b || a->type != b->type)
return -1;
switch (a->type) {
case V_ASN1_OBJECT:
result = OBJ_cmp(a->value.object, b->value.object);
break;
case V_ASN1_BOOLEAN:
result = a->value.boolean - b->value.boolean;
break;
case V_ASN1_NULL:
result = 0; /* They do not have content. */
break;
case V_ASN1_INTEGER:
case V_ASN1_NEG_INTEGER:
case V_ASN1_ENUMERATED:
case V_ASN1_NEG_ENUMERATED:
case V_ASN1_BIT_STRING:
case V_ASN1_OCTET_STRING:
case V_ASN1_SEQUENCE:
case V_ASN1_SET:
case V_ASN1_NUMERICSTRING:
case V_ASN1_PRINTABLESTRING:
case V_ASN1_T61STRING:
case V_ASN1_VIDEOTEXSTRING:
case V_ASN1_IA5STRING:
case V_ASN1_UTCTIME:
case V_ASN1_GENERALIZEDTIME:
case V_ASN1_GRAPHICSTRING:
case V_ASN1_VISIBLESTRING:
case V_ASN1_GENERALSTRING:
case V_ASN1_UNIVERSALSTRING:
case V_ASN1_BMPSTRING:
case V_ASN1_UTF8STRING:
case V_ASN1_OTHER:
default:
result = ASN1_STRING_cmp((ASN1_STRING *)a->value.ptr,
(ASN1_STRING *)b->value.ptr);
break;
}
return result;
}
|
CWE-119
| 18,225
|
rsvg_mask_parse (const RsvgDefs * defs, const char *str)
{
char *name;
name = rsvg_get_url_string (str);
if (name) {
RsvgNode *val;
val = rsvg_defs_lookup (defs, name);
g_free (name);
if (val && RSVG_NODE_TYPE (val) == RSVG_NODE_TYPE_MASK)
return val;
}
return NULL;
}
|
CWE-20
| 18,237
|
rsvg_state_clone (RsvgState * dst, const RsvgState * src)
{
gint i;
RsvgState *parent = dst->parent;
rsvg_state_finalize (dst);
*dst = *src;
dst->parent = parent;
dst->font_family = g_strdup (src->font_family);
dst->lang = g_strdup (src->lang);
rsvg_paint_server_ref (dst->fill);
rsvg_paint_server_ref (dst->stroke);
dst->styles = g_hash_table_ref (src->styles);
if (src->dash.n_dash > 0) {
dst->dash.dash = g_new (gdouble, src->dash.n_dash);
for (i = 0; i < src->dash.n_dash; i++)
dst->dash.dash[i] = src->dash.dash[i];
}
}
|
CWE-20
| 18,238
|
rsvg_state_finalize (RsvgState * state)
{
g_free (state->font_family);
g_free (state->lang);
rsvg_paint_server_unref (state->fill);
rsvg_paint_server_unref (state->stroke);
if (state->dash.n_dash != 0)
g_free (state->dash.dash);
if (state->styles) {
g_hash_table_unref (state->styles);
state->styles = NULL;
}
}
|
CWE-20
| 18,241
|
Address Zone::NewExpand(int size) {
// Make sure the requested size is already properly aligned and that
// there isn't enough room in the Zone to satisfy the request.
ASSERT(size == RoundDown(size, kAlignment));
ASSERT(size > limit_ - position_);
// Compute the new segment size. We use a 'high water mark'
// strategy, where we increase the segment size every time we expand
// except that we employ a maximum segment size when we delete. This
// is to avoid excessive malloc() and free() overhead.
Segment* head = segment_head_;
int old_size = (head == NULL) ? 0 : head->size();
static const int kSegmentOverhead = sizeof(Segment) + kAlignment;
int new_size_no_overhead = size + (old_size << 1);
int new_size = kSegmentOverhead + new_size_no_overhead;
// Guard against integer overflow.
if (new_size_no_overhead < size || new_size < kSegmentOverhead) {
V8::FatalProcessOutOfMemory("Zone");
return NULL;
}
if (new_size < kMinimumSegmentSize) {
new_size = kMinimumSegmentSize;
} else if (new_size > kMaximumSegmentSize) {
// Limit the size of new segments to avoid growing the segment size
// exponentially, thus putting pressure on contiguous virtual address space.
// All the while making sure to allocate a segment large enough to hold the
// requested size.
new_size = Max(kSegmentOverhead + size, kMaximumSegmentSize);
}
Segment* segment = NewSegment(new_size);
if (segment == NULL) {
V8::FatalProcessOutOfMemory("Zone");
return NULL;
}
// Recompute 'top' and 'limit' based on the new segment.
Address result = RoundUp(segment->start(), kAlignment);
position_ = result + size;
// Check for address overflow.
if (position_ < result) {
V8::FatalProcessOutOfMemory("Zone");
return NULL;
}
limit_ = segment->end();
ASSERT(position_ <= limit_);
return result;
}
|
CWE-119
| 18,249
|
inline void* Zone::New(int size) {
ASSERT(scope_nesting_ > 0);
// Round up the requested size to fit the alignment.
size = RoundUp(size, kAlignment);
// If the allocation size is divisible by 8 then we return an 8-byte aligned
// address.
if (kPointerSize == 4 && kAlignment == 4) {
position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4);
} else {
ASSERT(kAlignment >= kPointerSize);
}
// Check if the requested size is available without expanding.
Address result = position_;
if (size > limit_ - position_) {
result = NewExpand(size);
} else {
position_ += size;
}
// Check that the result has the proper alignment and return it.
ASSERT(IsAddressAligned(result, kAlignment, 0));
allocation_size_ += size;
return reinterpret_cast<void*>(result);
}
|
CWE-119
| 18,250
|
pattern_get_fallback (gpointer data)
{
RsvgPattern *pattern = data;
return pattern->fallback;
}
|
CWE-125
| 18,264
|
pattern_apply_fallback (gpointer data, gpointer fallback_data)
{
RsvgPattern *pattern;
RsvgPattern *fallback;
pattern = data;
fallback = fallback_data;
if (!pattern->hasx && fallback->hasx) {
pattern->hasx = TRUE;
pattern->x = fallback->x;
}
if (!pattern->hasy && fallback->hasy) {
pattern->hasy = TRUE;
pattern->y = fallback->y;
}
if (!pattern->haswidth && fallback->haswidth) {
pattern->haswidth = TRUE;
pattern->width = fallback->width;
}
if (!pattern->hasheight && fallback->hasheight) {
pattern->hasheight = TRUE;
pattern->height = fallback->height;
}
if (!pattern->hastransform && fallback->hastransform) {
pattern->hastransform = TRUE;
pattern->affine = fallback->affine;
}
if (!pattern->hasvbox && fallback->hasvbox) {
pattern->vbox = fallback->vbox;
}
if (!pattern->hasaspect && fallback->hasaspect) {
pattern->hasaspect = TRUE;
pattern->preserve_aspect_ratio = fallback->preserve_aspect_ratio;
}
if (!pattern->hasbbox && fallback->hasbbox) {
pattern->hasbbox = TRUE;
pattern->obj_bbox = fallback->obj_bbox;
}
if (!pattern->hascbox && fallback->hascbox) {
pattern->hascbox = TRUE;
pattern->obj_cbbox = fallback->obj_cbbox;
}
if (!pattern->super.children->len && fallback->super.children->len) {
pattern->super.children = fallback->super.children;
}
}
|
CWE-125
| 18,265
|
int TS_OBJ_print_bio(BIO *bio, const ASN1_OBJECT *obj)
{
char obj_txt[128];
int len = OBJ_obj2txt(obj_txt, sizeof(obj_txt), obj, 0);
BIO_write(bio, obj_txt, len);
BIO_write(bio, "\n", 1);
return 1;
}
|
CWE-125
| 18,268
|
int MDC2_Update(MDC2_CTX *c, const unsigned char *in, size_t len)
{
size_t i, j;
i = c->num;
if (i != 0) {
if (i + len < MDC2_BLOCK) {
/* partial block */
memcpy(&(c->data[i]), in, len);
c->num += (int)len;
return 1;
} else {
/* filled one */
j = MDC2_BLOCK - i;
memcpy(&(c->data[i]), in, j);
len -= j;
in += j;
c->num = 0;
mdc2_body(c, &(c->data[0]), MDC2_BLOCK);
}
}
i = len & ~((size_t)MDC2_BLOCK - 1);
if (i > 0)
mdc2_body(c, in, i);
j = len - i;
if (j > 0) {
memcpy(&(c->data[0]), &(in[i]), j);
c->num = (int)j;
}
return 1;
}
|
CWE-787
| 18,285
|
PixarLogSetupDecode(TIFF* tif)
{
static const char module[] = "PixarLogSetupDecode";
TIFFDirectory *td = &tif->tif_dir;
PixarLogState* sp = DecoderState(tif);
tmsize_t tbuf_size;
assert(sp != NULL);
/* Make sure no byte swapping happens on the data
* after decompression. */
tif->tif_postdecode = _TIFFNoPostDecode;
/* for some reason, we can't do this in TIFFInitPixarLog */
sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
td->td_samplesperpixel : 1);
tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_imagewidth),
td->td_rowsperstrip), sizeof(uint16));
/* add one more stride in case input ends mid-stride */
tbuf_size = add_ms(tbuf_size, sizeof(uint16) * sp->stride);
if (tbuf_size == 0)
return (0); /* TODO: this is an error return without error report through TIFFErrorExt */
sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
if (sp->tbuf == NULL)
return (0);
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
sp->user_datafmt = PixarLogGuessDataFmt(td);
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
TIFFErrorExt(tif->tif_clientdata, module,
"PixarLog compression can't handle bits depth/data format combination (depth: %d)",
td->td_bitspersample);
return (0);
}
if (inflateInit(&sp->stream) != Z_OK) {
TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg ? sp->stream.msg : "(null)");
return (0);
} else {
sp->state |= PLSTATE_INIT;
return (1);
}
}
|
CWE-787
| 18,313
|
TIFFFlushData1(TIFF* tif)
{
if (tif->tif_rawcc > 0 && tif->tif_flags & TIFF_BUF4WRITE ) {
if (!isFillOrder(tif, tif->tif_dir.td_fillorder) &&
(tif->tif_flags & TIFF_NOBITREV) == 0)
TIFFReverseBits((uint8*)tif->tif_rawdata,
tif->tif_rawcc);
if (!TIFFAppendToStrip(tif,
isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip,
tif->tif_rawdata, tif->tif_rawcc))
return (0);
tif->tif_rawcc = 0;
tif->tif_rawcp = tif->tif_rawdata;
}
return (1);
}
|
CWE-119
| 18,318
|
reverseSamplesBytes (uint16 spp, uint16 bps, uint32 width,
uint8 *src, uint8 *dst)
{
int i;
uint32 col, bytes_per_pixel, col_offset;
uint8 bytebuff1;
unsigned char swapbuff[32];
if ((src == NULL) || (dst == NULL))
{
TIFFError("reverseSamplesBytes","Invalid input or output buffer");
return (1);
}
bytes_per_pixel = ((bps * spp) + 7) / 8;
switch (bps / 8)
{
case 8: /* Use memcpy for multiple bytes per sample data */
case 4:
case 3:
case 2: for (col = 0; col < (width / 2); col++)
{
col_offset = col * bytes_per_pixel;
_TIFFmemcpy (swapbuff, src + col_offset, bytes_per_pixel);
_TIFFmemcpy (src + col_offset, dst - col_offset - bytes_per_pixel, bytes_per_pixel);
_TIFFmemcpy (dst - col_offset - bytes_per_pixel, swapbuff, bytes_per_pixel);
}
break;
case 1: /* Use byte copy only for single byte per sample data */
for (col = 0; col < (width / 2); col++)
{
for (i = 0; i < spp; i++)
{
bytebuff1 = *src;
*src++ = *(dst - spp + i);
*(dst - spp + i) = bytebuff1;
}
dst -= spp;
}
break;
default: TIFFError("reverseSamplesBytes","Unsupported bit depth %d", bps);
return (1);
}
return (0);
} /* end reverseSamplesBytes */
|
CWE-119
| 18,322
|
horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc)
{
TIFFPredictorState* sp = PredictorState(tif);
tmsize_t stride = sp->stride;
unsigned char* cp = (unsigned char*) cp0;
assert((cc%stride)==0);
if (cc > stride) {
cc -= stride;
/*
* Pipeline the most common cases.
*/
if (stride == 3) {
unsigned int r1, g1, b1;
unsigned int r2 = cp[0];
unsigned int g2 = cp[1];
unsigned int b2 = cp[2];
do {
r1 = cp[3]; cp[3] = (unsigned char)((r1-r2)&0xff); r2 = r1;
g1 = cp[4]; cp[4] = (unsigned char)((g1-g2)&0xff); g2 = g1;
b1 = cp[5]; cp[5] = (unsigned char)((b1-b2)&0xff); b2 = b1;
cp += 3;
} while ((cc -= 3) > 0);
} else if (stride == 4) {
unsigned int r1, g1, b1, a1;
unsigned int r2 = cp[0];
unsigned int g2 = cp[1];
unsigned int b2 = cp[2];
unsigned int a2 = cp[3];
do {
r1 = cp[4]; cp[4] = (unsigned char)((r1-r2)&0xff); r2 = r1;
g1 = cp[5]; cp[5] = (unsigned char)((g1-g2)&0xff); g2 = g1;
b1 = cp[6]; cp[6] = (unsigned char)((b1-b2)&0xff); b2 = b1;
a1 = cp[7]; cp[7] = (unsigned char)((a1-a2)&0xff); a2 = a1;
cp += 4;
} while ((cc -= 4) > 0);
} else {
cp += cc - 1;
do {
REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0])&0xff); cp--)
} while ((cc -= stride) > 0);
}
}
}
|
CWE-119
| 18,325
|
horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc)
{
tmsize_t stride = PredictorState(tif)->stride;
unsigned char* cp = (unsigned char*) cp0;
assert((cc%stride)==0);
if (cc > stride) {
/*
* Pipeline the most common cases.
*/
if (stride == 3) {
unsigned int cr = cp[0];
unsigned int cg = cp[1];
unsigned int cb = cp[2];
cc -= 3;
cp += 3;
while (cc>0) {
cp[0] = (unsigned char) ((cr += cp[0]) & 0xff);
cp[1] = (unsigned char) ((cg += cp[1]) & 0xff);
cp[2] = (unsigned char) ((cb += cp[2]) & 0xff);
cc -= 3;
cp += 3;
}
} else if (stride == 4) {
unsigned int cr = cp[0];
unsigned int cg = cp[1];
unsigned int cb = cp[2];
unsigned int ca = cp[3];
cc -= 4;
cp += 4;
while (cc>0) {
cp[0] = (unsigned char) ((cr += cp[0]) & 0xff);
cp[1] = (unsigned char) ((cg += cp[1]) & 0xff);
cp[2] = (unsigned char) ((cb += cp[2]) & 0xff);
cp[3] = (unsigned char) ((ca += cp[3]) & 0xff);
cc -= 4;
cp += 4;
}
} else {
cc -= stride;
do {
REPEAT4(stride, cp[stride] =
(unsigned char) ((cp[stride] + *cp) & 0xff); cp++)
cc -= stride;
} while (cc>0);
}
}
}
|
CWE-119
| 18,326
|
PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
{
TIFFPredictorState *sp = PredictorState(tif);
assert(sp != NULL);
assert(sp->decoderow != NULL);
assert(sp->decodepfunc != NULL);
if ((*sp->decoderow)(tif, op0, occ0, s)) {
(*sp->decodepfunc)(tif, op0, occ0);
return 1;
} else
return 0;
}
|
CWE-119
| 18,327
|
horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc)
{
TIFFPredictorState* sp = PredictorState(tif);
tmsize_t stride = sp->stride;
uint32 *wp = (uint32*) cp0;
tmsize_t wc = cc/4;
assert((cc%(4*stride))==0);
if (wc > stride) {
wc -= stride;
wp += wc - 1;
do {
REPEAT4(stride, wp[stride] -= wp[0]; wp--)
wc -= stride;
} while (wc > 0);
}
}
|
CWE-119
| 18,328
|
PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
{
TIFFPredictorState *sp = PredictorState(tif);
assert(sp != NULL);
assert(sp->decodetile != NULL);
if ((*sp->decodetile)(tif, op0, occ0, s)) {
tmsize_t rowsize = sp->rowsize;
assert(rowsize > 0);
assert((occ0%rowsize)==0);
assert(sp->decodepfunc != NULL);
while (occ0 > 0) {
(*sp->decodepfunc)(tif, op0, rowsize);
occ0 -= rowsize;
op0 += rowsize;
}
return 1;
} else
return 0;
}
|
CWE-119
| 18,329
|
horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc)
{
TIFFPredictorState* sp = PredictorState(tif);
tmsize_t stride = sp->stride;
uint16 *wp = (uint16*) cp0;
tmsize_t wc = cc/2;
assert((cc%(2*stride))==0);
if (wc > stride) {
wc -= stride;
wp += wc - 1;
do {
REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[stride] - (unsigned int)wp[0]) & 0xffff); wp--)
wc -= stride;
} while (wc > 0);
}
}
|
CWE-119
| 18,330
|
PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s)
{
static const char module[] = "PredictorEncodeTile";
TIFFPredictorState *sp = PredictorState(tif);
uint8 *working_copy;
tmsize_t cc = cc0, rowsize;
unsigned char* bp;
int result_code;
assert(sp != NULL);
assert(sp->encodepfunc != NULL);
assert(sp->encodetile != NULL);
/*
* Do predictor manipulation in a working buffer to avoid altering
* the callers buffer. http://trac.osgeo.org/gdal/ticket/1965
*/
working_copy = (uint8*) _TIFFmalloc(cc0);
if( working_copy == NULL )
{
TIFFErrorExt(tif->tif_clientdata, module,
"Out of memory allocating " TIFF_SSIZE_FORMAT " byte temp buffer.",
cc0 );
return 0;
}
memcpy( working_copy, bp0, cc0 );
bp = working_copy;
rowsize = sp->rowsize;
assert(rowsize > 0);
assert((cc0%rowsize)==0);
while (cc > 0) {
(*sp->encodepfunc)(tif, bp, rowsize);
cc -= rowsize;
bp += rowsize;
}
result_code = (*sp->encodetile)(tif, working_copy, cc0, s);
_TIFFfree( working_copy );
return result_code;
}
|
CWE-119
| 18,331
|
horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc)
{
tmsize_t stride = PredictorState(tif)->stride;
uint32* wp = (uint32*) cp0;
tmsize_t wc = cc / 4;
assert((cc%(4*stride))==0);
if (wc > stride) {
wc -= stride;
do {
REPEAT4(stride, wp[stride] += wp[0]; wp++)
wc -= stride;
} while (wc > 0);
}
}
|
CWE-119
| 18,332
|
PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
TIFFPredictorState *sp = PredictorState(tif);
assert(sp != NULL);
assert(sp->encodepfunc != NULL);
assert(sp->encoderow != NULL);
/* XXX horizontal differencing alters user's data XXX */
(*sp->encodepfunc)(tif, bp, cc);
return (*sp->encoderow)(tif, bp, cc, s);
}
|
CWE-119
| 18,333
|
swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc)
{
uint16* wp = (uint16*) cp0;
tmsize_t wc = cc / 2;
TIFFSwabArrayOfShort(wp, wc);
horAcc16(tif, cp0, cc);
}
|
CWE-119
| 18,334
|
swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc)
{
uint16* wp = (uint16*) cp0;
tmsize_t wc = cc / 2;
horDiff16(tif, cp0, cc);
TIFFSwabArrayOfShort(wp, wc);
}
|
CWE-119
| 18,335
|
swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc)
{
uint32* wp = (uint32*) cp0;
tmsize_t wc = cc / 4;
TIFFSwabArrayOfLong(wp, wc);
horAcc32(tif, cp0, cc);
}
|
CWE-119
| 18,336
|
fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc)
{
tmsize_t stride = PredictorState(tif)->stride;
uint32 bps = tif->tif_dir.td_bitspersample / 8;
tmsize_t wc = cc / bps;
tmsize_t count;
uint8 *cp = (uint8 *) cp0;
uint8 *tmp = (uint8 *)_TIFFmalloc(cc);
assert((cc%(bps*stride))==0);
if (!tmp)
return;
_TIFFmemcpy(tmp, cp0, cc);
for (count = 0; count < wc; count++) {
uint32 byte;
for (byte = 0; byte < bps; byte++) {
#if WORDS_BIGENDIAN
cp[byte * wc + count] = tmp[bps * count + byte];
#else
cp[(bps - byte - 1) * wc + count] =
tmp[bps * count + byte];
#endif
}
}
_TIFFfree(tmp);
cp = (uint8 *) cp0;
cp += cc - stride - 1;
for (count = cc; count > stride; count -= stride)
REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0])&0xff); cp--)
}
|
CWE-119
| 18,337
|
fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc)
{
tmsize_t stride = PredictorState(tif)->stride;
uint32 bps = tif->tif_dir.td_bitspersample / 8;
tmsize_t wc = cc / bps;
tmsize_t count = cc;
uint8 *cp = (uint8 *) cp0;
uint8 *tmp = (uint8 *)_TIFFmalloc(cc);
assert((cc%(bps*stride))==0);
if (!tmp)
return;
while (count > stride) {
REPEAT4(stride, cp[stride] =
(unsigned char) ((cp[stride] + cp[0]) & 0xff); cp++)
count -= stride;
}
_TIFFmemcpy(tmp, cp0, cc);
cp = (uint8 *) cp0;
for (count = 0; count < wc; count++) {
uint32 byte;
for (byte = 0; byte < bps; byte++) {
#if WORDS_BIGENDIAN
cp[bps * count + byte] = tmp[byte * wc + count];
#else
cp[bps * count + byte] =
tmp[(bps - byte - 1) * wc + count];
#endif
}
}
_TIFFfree(tmp);
}
|
CWE-119
| 18,338
|
swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc)
{
uint32* wp = (uint32*) cp0;
tmsize_t wc = cc / 4;
horDiff32(tif, cp0, cc);
TIFFSwabArrayOfLong(wp, wc);
}
|
CWE-119
| 18,339
|
horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc)
{
tmsize_t stride = PredictorState(tif)->stride;
uint16* wp = (uint16*) cp0;
tmsize_t wc = cc / 2;
assert((cc%(2*stride))==0);
if (wc > stride) {
wc -= stride;
do {
REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[stride] + (unsigned int)wp[0]) & 0xffff); wp++)
wc -= stride;
} while (wc > 0);
}
}
|
CWE-119
| 18,340
|
fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc)
{
tmsize_t stride = PredictorState(tif)->stride;
uint32 bps = tif->tif_dir.td_bitspersample / 8;
tmsize_t wc = cc / bps;
tmsize_t count;
uint8 *cp = (uint8 *) cp0;
uint8 *tmp = (uint8 *)_TIFFmalloc(cc);
if((cc%(bps*stride))!=0)
{
TIFFErrorExt(tif->tif_clientdata, "fpDiff",
"%s", "(cc%(bps*stride))!=0");
return 0;
}
if (!tmp)
return 0;
_TIFFmemcpy(tmp, cp0, cc);
for (count = 0; count < wc; count++) {
uint32 byte;
for (byte = 0; byte < bps; byte++) {
#if WORDS_BIGENDIAN
cp[byte * wc + count] = tmp[bps * count + byte];
#else
cp[(bps - byte - 1) * wc + count] =
tmp[bps * count + byte];
#endif
}
}
_TIFFfree(tmp);
cp = (uint8 *) cp0;
cp += cc - stride - 1;
for (count = cc; count > stride; count -= stride)
REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0])&0xff); cp--)
return 1;
}
|
CWE-119
| 18,341
|
fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc)
{
tmsize_t stride = PredictorState(tif)->stride;
uint32 bps = tif->tif_dir.td_bitspersample / 8;
tmsize_t wc = cc / bps;
tmsize_t count = cc;
uint8 *cp = (uint8 *) cp0;
uint8 *tmp = (uint8 *)_TIFFmalloc(cc);
if(cc%(bps*stride)!=0)
{
TIFFErrorExt(tif->tif_clientdata, "fpAcc",
"%s", "cc%(bps*stride))!=0");
return 0;
}
if (!tmp)
return 0;
while (count > stride) {
REPEAT4(stride, cp[stride] =
(unsigned char) ((cp[stride] + cp[0]) & 0xff); cp++)
count -= stride;
}
_TIFFmemcpy(tmp, cp0, cc);
cp = (uint8 *) cp0;
for (count = 0; count < wc; count++) {
uint32 byte;
for (byte = 0; byte < bps; byte++) {
#if WORDS_BIGENDIAN
cp[bps * count + byte] = tmp[byte * wc + count];
#else
cp[bps * count + byte] =
tmp[(bps - byte - 1) * wc + count];
#endif
}
}
_TIFFfree(tmp);
return 1;
}
|
CWE-119
| 18,342
|
PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s)
{
static const char module[] = "PredictorEncodeTile";
TIFFPredictorState *sp = PredictorState(tif);
uint8 *working_copy;
tmsize_t cc = cc0, rowsize;
unsigned char* bp;
int result_code;
assert(sp != NULL);
assert(sp->encodepfunc != NULL);
assert(sp->encodetile != NULL);
/*
* Do predictor manipulation in a working buffer to avoid altering
* the callers buffer. http://trac.osgeo.org/gdal/ticket/1965
*/
working_copy = (uint8*) _TIFFmalloc(cc0);
if( working_copy == NULL )
{
TIFFErrorExt(tif->tif_clientdata, module,
"Out of memory allocating " TIFF_SSIZE_FORMAT " byte temp buffer.",
cc0 );
return 0;
}
memcpy( working_copy, bp0, cc0 );
bp = working_copy;
rowsize = sp->rowsize;
assert(rowsize > 0);
if((cc0%rowsize)!=0)
{
TIFFErrorExt(tif->tif_clientdata, "PredictorEncodeTile",
"%s", "(cc0%rowsize)!=0");
return 0;
}
while (cc > 0) {
(*sp->encodepfunc)(tif, bp, rowsize);
cc -= rowsize;
bp += rowsize;
}
result_code = (*sp->encodetile)(tif, working_copy, cc0, s);
_TIFFfree( working_copy );
return result_code;
}
|
CWE-119
| 18,343
|
DECLAREreadFunc(readContigTilesIntoBuffer)
{
int status = 1;
tsize_t tilesize = TIFFTileSize(in);
tdata_t tilebuf;
uint32 imagew = TIFFScanlineSize(in);
uint32 tilew = TIFFTileRowSize(in);
int iskew = imagew - tilew;
uint8* bufp = (uint8*) buf;
uint32 tw, tl;
uint32 row;
(void) spp;
tilebuf = _TIFFmalloc(tilesize);
if (tilebuf == 0)
return 0;
_TIFFmemset(tilebuf, 0, tilesize);
(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);
(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);
for (row = 0; row < imagelength; row += tl) {
uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;
uint32 colb = 0;
uint32 col;
for (col = 0; col < imagewidth; col += tw) {
if (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0
&& !ignore) {
TIFFError(TIFFFileName(in),
"Error, can't read tile at %lu %lu",
(unsigned long) col,
(unsigned long) row);
status = 0;
goto done;
}
if (colb + tilew > imagew) {
uint32 width = imagew - colb;
uint32 oskew = tilew - width;
cpStripToTile(bufp + colb,
tilebuf, nrow, width,
oskew + iskew, oskew );
} else
cpStripToTile(bufp + colb,
tilebuf, nrow, tilew,
iskew, 0);
colb += tilew;
}
bufp += imagew * nrow;
}
done:
_TIFFfree(tilebuf);
return status;
}
|
CWE-119
| 18,348
|
DECLAREwriteFunc(writeBufferToContigTiles)
{
uint32 imagew = TIFFScanlineSize(out);
uint32 tilew = TIFFTileRowSize(out);
int iskew = imagew - tilew;
tsize_t tilesize = TIFFTileSize(out);
tdata_t obuf;
uint8* bufp = (uint8*) buf;
uint32 tl, tw;
uint32 row;
(void) spp;
obuf = _TIFFmalloc(TIFFTileSize(out));
if (obuf == NULL)
return 0;
_TIFFmemset(obuf, 0, tilesize);
(void) TIFFGetField(out, TIFFTAG_TILELENGTH, &tl);
(void) TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw);
for (row = 0; row < imagelength; row += tilelength) {
uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;
uint32 colb = 0;
uint32 col;
for (col = 0; col < imagewidth; col += tw) {
/*
* Tile is clipped horizontally. Calculate
* visible portion and skewing factors.
*/
if (colb + tilew > imagew) {
uint32 width = imagew - colb;
int oskew = tilew - width;
cpStripToTile(obuf, bufp + colb, nrow, width,
oskew, oskew + iskew);
} else
cpStripToTile(obuf, bufp + colb, nrow, tilew,
0, iskew);
if (TIFFWriteTile(out, obuf, col, row, 0, 0) < 0) {
TIFFError(TIFFFileName(out),
"Error, can't write tile at %lu %lu",
(unsigned long) col,
(unsigned long) row);
_TIFFfree(obuf);
return 0;
}
colb += tilew;
}
bufp += nrow * imagew;
}
_TIFFfree(obuf);
return 1;
}
|
CWE-119
| 18,349
|
static int readContigStripsIntoBuffer (TIFF* in, uint8* buf)
{
uint8* bufp = buf;
int32 bytes_read = 0;
uint32 strip, nstrips = TIFFNumberOfStrips(in);
uint32 stripsize = TIFFStripSize(in);
uint32 rows = 0;
uint32 rps = TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rps);
tsize_t scanline_size = TIFFScanlineSize(in);
if (scanline_size == 0) {
TIFFError("", "TIFF scanline size is zero!");
return 0;
}
for (strip = 0; strip < nstrips; strip++) {
bytes_read = TIFFReadEncodedStrip (in, strip, bufp, -1);
rows = bytes_read / scanline_size;
if ((strip < (nstrips - 1)) && (bytes_read != (int32)stripsize))
TIFFError("", "Strip %d: read %lu bytes, strip size %lu",
(int)strip + 1, (unsigned long) bytes_read,
(unsigned long)stripsize);
if (bytes_read < 0 && !ignore) {
TIFFError("", "Error reading strip %lu after %lu rows",
(unsigned long) strip, (unsigned long)rows);
return 0;
}
bufp += bytes_read;
}
return 1;
} /* end readContigStripsIntoBuffer */
|
CWE-119
| 18,352
|
DECLAREreadFunc(readContigTilesIntoBuffer)
{
int status = 1;
tsize_t tilesize = TIFFTileSize(in);
tdata_t tilebuf;
uint32 imagew = TIFFScanlineSize(in);
uint32 tilew = TIFFTileRowSize(in);
int iskew = imagew - tilew;
uint8* bufp = (uint8*) buf;
uint32 tw, tl;
uint32 row;
(void) spp;
tilebuf = _TIFFmalloc(tilesize);
if (tilebuf == 0)
return 0;
_TIFFmemset(tilebuf, 0, tilesize);
(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);
(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);
for (row = 0; row < imagelength; row += tl) {
uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;
uint32 colb = 0;
uint32 col;
for (col = 0; col < imagewidth && colb < imagew; col += tw) {
if (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0
&& !ignore) {
TIFFError(TIFFFileName(in),
"Error, can't read tile at %lu %lu",
(unsigned long) col,
(unsigned long) row);
status = 0;
goto done;
}
if (colb + tilew > imagew) {
uint32 width = imagew - colb;
uint32 oskew = tilew - width;
cpStripToTile(bufp + colb,
tilebuf, nrow, width,
oskew + iskew, oskew );
} else
cpStripToTile(bufp + colb,
tilebuf, nrow, tilew,
iskew, 0);
colb += tilew;
}
bufp += imagew * nrow;
}
done:
_TIFFfree(tilebuf);
return status;
}
|
CWE-119
| 18,353
|
cpStripToTile(uint8* out, uint8* in,
uint32 rows, uint32 cols, int outskew, int inskew)
{
while (rows-- > 0) {
uint32 j = cols;
while (j-- > 0)
*out++ = *in++;
out += outskew;
in += inskew;
}
}
|
CWE-119
| 18,354
|
DECLAREcpFunc(cpContig2SeparateByRow)
{
tsize_t scanlinesizein = TIFFScanlineSize(in);
tsize_t scanlinesizeout = TIFFScanlineSize(out);
tdata_t inbuf;
tdata_t outbuf;
register uint8 *inp, *outp;
register uint32 n;
uint32 row;
tsample_t s;
inbuf = _TIFFmalloc(scanlinesizein);
outbuf = _TIFFmalloc(scanlinesizeout);
if (!inbuf || !outbuf)
goto bad;
_TIFFmemset(inbuf, 0, scanlinesizein);
_TIFFmemset(outbuf, 0, scanlinesizeout);
/* unpack channels */
for (s = 0; s < spp; s++) {
for (row = 0; row < imagelength; row++) {
if (TIFFReadScanline(in, inbuf, row, 0) < 0
&& !ignore) {
TIFFError(TIFFFileName(in),
"Error, can't read scanline %lu",
(unsigned long) row);
goto bad;
}
inp = ((uint8*)inbuf) + s;
outp = (uint8*)outbuf;
for (n = imagewidth; n-- > 0;) {
*outp++ = *inp;
inp += spp;
}
if (TIFFWriteScanline(out, outbuf, row, s) < 0) {
TIFFError(TIFFFileName(out),
"Error, can't write scanline %lu",
(unsigned long) row);
goto bad;
}
}
}
if (inbuf) _TIFFfree(inbuf);
if (outbuf) _TIFFfree(outbuf);
return 1;
bad:
if (inbuf) _TIFFfree(inbuf);
if (outbuf) _TIFFfree(outbuf);
return 0;
}
|
CWE-119
| 18,363
|
DECLAREcpFunc(cpSeparate2ContigByRow)
{
tsize_t scanlinesizein = TIFFScanlineSize(in);
tsize_t scanlinesizeout = TIFFScanlineSize(out);
tdata_t inbuf;
tdata_t outbuf;
register uint8 *inp, *outp;
register uint32 n;
uint32 row;
tsample_t s;
inbuf = _TIFFmalloc(scanlinesizein);
outbuf = _TIFFmalloc(scanlinesizeout);
if (!inbuf || !outbuf)
goto bad;
_TIFFmemset(inbuf, 0, scanlinesizein);
_TIFFmemset(outbuf, 0, scanlinesizeout);
for (row = 0; row < imagelength; row++) {
/* merge channels */
for (s = 0; s < spp; s++) {
if (TIFFReadScanline(in, inbuf, row, s) < 0
&& !ignore) {
TIFFError(TIFFFileName(in),
"Error, can't read scanline %lu",
(unsigned long) row);
goto bad;
}
inp = (uint8*)inbuf;
outp = ((uint8*)outbuf) + s;
for (n = imagewidth; n-- > 0;) {
*outp = *inp++;
outp += spp;
}
}
if (TIFFWriteScanline(out, outbuf, row, 0) < 0) {
TIFFError(TIFFFileName(out),
"Error, can't write scanline %lu",
(unsigned long) row);
goto bad;
}
}
if (inbuf) _TIFFfree(inbuf);
if (outbuf) _TIFFfree(outbuf);
return 1;
bad:
if (inbuf) _TIFFfree(inbuf);
if (outbuf) _TIFFfree(outbuf);
return 0;
}
|
CWE-119
| 18,365
|
static int rc4_hmac_md5_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
void *ptr)
{
EVP_RC4_HMAC_MD5 *key = data(ctx);
switch (type) {
case EVP_CTRL_AEAD_SET_MAC_KEY:
{
unsigned int i;
unsigned char hmac_key[64];
memset(hmac_key, 0, sizeof(hmac_key));
if (arg > (int)sizeof(hmac_key)) {
MD5_Init(&key->head);
MD5_Update(&key->head, ptr, arg);
MD5_Final(hmac_key, &key->head);
} else {
memcpy(hmac_key, ptr, arg);
}
for (i = 0; i < sizeof(hmac_key); i++)
hmac_key[i] ^= 0x36; /* ipad */
MD5_Init(&key->head);
MD5_Update(&key->head, hmac_key, sizeof(hmac_key));
for (i = 0; i < sizeof(hmac_key); i++)
hmac_key[i] ^= 0x36 ^ 0x5c; /* opad */
MD5_Init(&key->tail);
MD5_Update(&key->tail, hmac_key, sizeof(hmac_key));
OPENSSL_cleanse(hmac_key, sizeof(hmac_key));
return 1;
}
case EVP_CTRL_AEAD_TLS1_AAD:
{
unsigned char *p = ptr;
unsigned int len;
if (arg != EVP_AEAD_TLS1_AAD_LEN)
return -1;
len = p[arg - 2] << 8 | p[arg - 1];
if (!EVP_CIPHER_CTX_encrypting(ctx)) {
len -= MD5_DIGEST_LENGTH;
p[arg - 2] = len >> 8;
p[arg - 1] = len;
}
key->payload_length = len;
key->md = key->head;
MD5_Update(&key->md, p, arg);
return MD5_DIGEST_LENGTH;
}
default:
return -1;
}
}
|
CWE-125
| 18,369
|
static void mysql_prune_stmt_list(MYSQL *mysql)
{
LIST *element= mysql->stmts;
LIST *pruned_list= 0;
for (; element; element= element->next)
{
MYSQL_STMT *stmt= (MYSQL_STMT *) element->data;
if (stmt->state != MYSQL_STMT_INIT_DONE)
{
stmt->mysql= 0;
stmt->last_errno= CR_SERVER_LOST;
strmov(stmt->last_error, ER(CR_SERVER_LOST));
strmov(stmt->sqlstate, unknown_sqlstate);
}
else
{
pruned_list= list_add(pruned_list, element);
}
}
mysql->stmts= pruned_list;
}
|
CWE-416
| 18,380
|
TIFFNumberOfStrips(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
uint32 nstrips;
/* If the value was already computed and store in td_nstrips, then return it,
since ChopUpSingleUncompressedStrip might have altered and resized the
since the td_stripbytecount and td_stripoffset arrays to the new value
after the initial affectation of td_nstrips = TIFFNumberOfStrips() in
tif_dirread.c ~line 3612.
See http://bugzilla.maptools.org/show_bug.cgi?id=2587 */
if( td->td_nstrips )
return td->td_nstrips;
nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :
TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
nstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel,
"TIFFNumberOfStrips");
return (nstrips);
}
|
CWE-125
| 18,399
|
LogLuvClose(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
/*
* For consistency, we always want to write out the same
* bitspersample and sampleformat for our TIFF file,
* regardless of the data format being used by the application.
* Since this routine is called after tags have been set but
* before they have been recorded in the file, we reset them here.
*/
td->td_samplesperpixel =
(td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3;
td->td_bitspersample = 16;
td->td_sampleformat = SAMPLEFORMAT_INT;
}
|
CWE-125
| 18,401
|
PixarLogClose(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
/* In a really sneaky (and really incorrect, and untruthful, and
* troublesome, and error-prone) maneuver that completely goes against
* the spirit of TIFF, and breaks TIFF, on close, we covertly
* modify both bitspersample and sampleformat in the directory to
* indicate 8-bit linear. This way, the decode "just works" even for
* readers that don't know about PixarLog, or how to set
* the PIXARLOGDATFMT pseudo-tag.
*/
td->td_bitspersample = 8;
td->td_sampleformat = SAMPLEFORMAT_UINT;
}
|
CWE-125
| 18,403
|
DECLAREContigPutFunc(putagreytile)
{
int samplesperpixel = img->samplesperpixel;
uint32** BWmap = img->BWmap;
(void) y;
while (h-- > 0) {
for (x = w; x-- > 0;)
{
*cp++ = BWmap[*pp][0] & (*(pp+1) << 24 | ~A1);
pp += samplesperpixel;
}
cp += toskew;
pp += fromskew;
}
}
|
CWE-20
| 18,409
|
TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size)
{
static const char module[] = "TIFFReadBufferSetup";
assert((tif->tif_flags&TIFF_NOREADRAW)==0);
tif->tif_flags &= ~TIFF_BUFFERMMAP;
if (tif->tif_rawdata) {
if (tif->tif_flags & TIFF_MYBUFFER)
_TIFFfree(tif->tif_rawdata);
tif->tif_rawdata = NULL;
tif->tif_rawdatasize = 0;
}
if (bp) {
tif->tif_rawdatasize = size;
tif->tif_rawdata = (uint8*) bp;
tif->tif_flags &= ~TIFF_MYBUFFER;
} else {
tif->tif_rawdatasize = (tmsize_t)TIFFroundup_64((uint64)size, 1024);
if (tif->tif_rawdatasize==0) {
TIFFErrorExt(tif->tif_clientdata, module,
"Invalid buffer size");
return (0);
}
tif->tif_rawdata = (uint8*) _TIFFmalloc(tif->tif_rawdatasize);
tif->tif_flags |= TIFF_MYBUFFER;
}
if (tif->tif_rawdata == NULL) {
TIFFErrorExt(tif->tif_clientdata, module,
"No space for data buffer at scanline %lu",
(unsigned long) tif->tif_row);
tif->tif_rawdatasize = 0;
return (0);
}
return (1);
}
|
CWE-119
| 18,410
|
TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value)
{
static const char module[] = "TIFFWriteDirectoryTagCheckedRational";
uint32 m[2];
assert(sizeof(uint32)==4);
if( value < 0 )
{
TIFFErrorExt(tif->tif_clientdata,module,"Negative value is illegal");
return 0;
}
else if (value==0.0)
{
m[0]=0;
m[1]=1;
}
else if (value==(double)(uint32)value)
{
m[0]=(uint32)value;
m[1]=1;
}
else if (value<1.0)
{
m[0]=(uint32)(value*0xFFFFFFFF);
m[1]=0xFFFFFFFF;
}
else
{
m[0]=0xFFFFFFFF;
m[1]=(uint32)(0xFFFFFFFF/value);
}
if (tif->tif_flags&TIFF_SWAB)
{
TIFFSwabLong(&m[0]);
TIFFSwabLong(&m[1]);
}
return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,1,8,&m[0]));
}
|
CWE-20
| 18,415
|
TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value)
{
static const char module[] = "TIFFWriteDirectoryTagCheckedRationalArray";
uint32* m;
float* na;
uint32* nb;
uint32 nc;
int o;
assert(sizeof(uint32)==4);
m=_TIFFmalloc(count*2*sizeof(uint32));
if (m==NULL)
{
TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
return(0);
}
for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
{
if (*na<=0.0)
{
nb[0]=0;
nb[1]=1;
}
else if (*na==(float)(uint32)(*na))
{
nb[0]=(uint32)(*na);
nb[1]=1;
}
else if (*na<1.0)
{
nb[0]=(uint32)((double)(*na)*0xFFFFFFFF);
nb[1]=0xFFFFFFFF;
}
else
{
nb[0]=0xFFFFFFFF;
nb[1]=(uint32)((double)0xFFFFFFFF/(*na));
}
}
if (tif->tif_flags&TIFF_SWAB)
TIFFSwabArrayOfLong(m,count*2);
o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,count,count*8,&m[0]);
_TIFFfree(m);
return(o);
}
|
CWE-20
| 18,416
|
sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels, int normalize)
{ static double data [BUFFER_LEN], max ;
sf_count_t frames, readcount, k ;
frames = BUFFER_LEN / channels ;
readcount = frames ;
sf_command (infile, SFC_CALC_SIGNAL_MAX, &max, sizeof (max)) ;
if (!normalize && max < 1.0)
{ while (readcount > 0)
{ readcount = sf_readf_double (infile, data, frames) ;
sf_writef_double (outfile, data, readcount) ;
} ;
}
else
{ sf_command (infile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
while (readcount > 0)
{ readcount = sf_readf_double (infile, data, frames) ;
for (k = 0 ; k < readcount * channels ; k++)
data [k] /= max ;
sf_writef_double (outfile, data, readcount) ;
} ;
} ;
return ;
} /* sfe_copy_data_fp */
|
CWE-125
| 18,439
|
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
const ASN1_ITEM *it,
int tag, int aclass, char opt, ASN1_TLC *ctx)
{
int rv;
rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx);
if (rv <= 0)
ASN1_item_ex_free(pval, it);
return rv;
}
|
CWE-787
| 18,447
|
void SimpleModule::runPull()
{
pull(m_outChunk->frameCount);
run(*m_inChunk, *m_outChunk);
}
|
CWE-787
| 18,469
|
static bool imap_parser_read_string(struct imap_parser *parser,
const unsigned char *data, size_t data_size)
{
size_t i;
/* read until we've found non-escaped ", CR or LF */
for (i = parser->cur_pos; i < data_size; i++) {
if (data[i] == '"') {
imap_parser_save_arg(parser, data, i);
i++; /* skip the trailing '"' too */
break;
}
if (data[i] == '\\') {
if (i+1 == data_size) {
/* known data ends with '\' - leave it to
next time as well if it happens to be \" */
break;
}
/* save the first escaped char */
if (parser->str_first_escape < 0)
parser->str_first_escape = i;
/* skip the escaped char */
i++;
}
/* check linebreaks here, so escaping CR/LF isn't possible.
string always ends with '"', so it's an error if we found
a linebreak.. */
if (is_linebreak(data[i]) &&
(parser->flags & IMAP_PARSE_FLAG_MULTILINE_STR) == 0) {
parser->error = IMAP_PARSE_ERROR_BAD_SYNTAX;
parser->error_msg = "Missing '\"'";
return FALSE;
}
}
parser->cur_pos = i;
return parser->cur_type == ARG_PARSE_NONE;
}
|
CWE-787
| 18,533
|
static void snippet_add_content(struct snippet_context *ctx,
struct snippet_data *target,
const unsigned char *data, size_t size,
size_t *count_r)
{
i_assert(target != NULL);
if (size >= 3 &&
((data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF) ||
(data[0] == 0xBF && data[1] == 0xBB && data[2] == 0xEF))) {
*count_r = 3;
return;
}
if (data[0] == '\0') {
/* skip NULs without increasing snippet size */
return;
}
if (i_isspace(*data)) {
/* skip any leading whitespace */
if (str_len(target->snippet) > 1)
ctx->add_whitespace = TRUE;
if (data[0] == '\n')
ctx->state = SNIPPET_STATE_NEWLINE;
return;
}
if (ctx->add_whitespace) {
str_append_c(target->snippet, ' ');
ctx->add_whitespace = FALSE;
if (target->chars_left-- == 0)
return;
}
if (target->chars_left == 0)
return;
target->chars_left--;
*count_r = uni_utf8_char_bytes(data[0]);
i_assert(*count_r <= size);
str_append_data(target->snippet, data, *count_r);
}
|
CWE-20
| 18,591
|
static bool ntlmssp_check_buffer(const struct ntlmssp_buffer *buffer,
size_t data_size, const char **error)
{
uint32_t offset = read_le32(&buffer->offset);
uint16_t length = read_le16(&buffer->length);
uint16_t space = read_le16(&buffer->space);
/* Empty buffer is ok */
if (length == 0 && space == 0)
return TRUE;
if (offset >= data_size) {
*error = "buffer offset out of bounds";
return FALSE;
}
if (offset + space > data_size) {
*error = "buffer end out of bounds";
return FALSE;
}
return TRUE;
}
|
CWE-125
| 18,635
|
rpa_read_buffer(pool_t pool, const unsigned char **data,
const unsigned char *end, unsigned char **buffer)
{
const unsigned char *p = *data;
unsigned int len;
if (p > end)
return 0;
len = *p++;
if (p + len > end)
return 0;
*buffer = p_malloc(pool, len);
memcpy(*buffer, p, len);
*data += 1 + len;
return len;
}
|
CWE-125
| 18,636
|
int main(void)
{
static void (*const test_functions[])(void) = {
test_message_parser_small_blocks,
test_message_parser_stop_early,
test_message_parser_truncated_mime_headers,
test_message_parser_truncated_mime_headers2,
test_message_parser_truncated_mime_headers3,
test_message_parser_empty_multipart,
test_message_parser_duplicate_mime_boundary,
test_message_parser_garbage_suffix_mime_boundary,
test_message_parser_trailing_dashes,
test_message_parser_continuing_mime_boundary,
test_message_parser_continuing_truncated_mime_boundary,
test_message_parser_continuing_mime_boundary_reverse,
test_message_parser_long_mime_boundary,
test_message_parser_no_eoh,
test_message_parser_mime_part_nested_limit,
test_message_parser_mime_part_nested_limit_rfc822,
test_message_parser_mime_part_limit,
test_message_parser_mime_version,
test_message_parser_mime_version_missing,
NULL
};
return test_run(test_functions);
}
|
CWE-20
| 18,661
|
int Http2Stream::DoWrite(WriteWrap* req_wrap,
uv_buf_t* bufs,
size_t nbufs,
uv_stream_t* send_handle) {
CHECK_NULL(send_handle);
Http2Scope h2scope(this);
if (!IsWritable() || IsDestroyed()) {
req_wrap->Done(UV_EOF);
return 0;
}
Debug(this, "queuing %d buffers to send", id_, nbufs);
for (size_t i = 0; i < nbufs; ++i) {
// Store the req_wrap on the last write info in the queue, so that it is
// only marked as finished once all buffers associated with it are finished.
queue_.emplace(nghttp2_stream_write {
i == nbufs - 1 ? req_wrap : nullptr,
bufs[i]
});
IncrementAvailableOutboundLength(bufs[i].len);
}
CHECK_NE(nghttp2_session_resume_data(**session_, id_), NGHTTP2_ERR_NOMEM);
return 0;
}
|
CWE-416
| 18,662
|
bool TLSWrap::InvokeQueued(int status, const char* error_str) {
Debug(this, "InvokeQueued(%d, %s)", status, error_str);
if (!write_callback_scheduled_)
return false;
if (current_write_ != nullptr) {
WriteWrap* w = current_write_;
current_write_ = nullptr;
w->Done(status, error_str);
}
return true;
}
|
CWE-416
| 18,663
|
int DoWrite(WriteWrap* w,
uv_buf_t* bufs,
size_t count,
uv_stream_t* send_handle) override {
return UV_ENOSYS; // Not implemented (yet).
}
|
CWE-416
| 18,664
|
int JSStream::DoWrite(WriteWrap* w,
uv_buf_t* bufs,
size_t count,
uv_stream_t* send_handle) {
CHECK_NULL(send_handle);
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
Local<Array> bufs_arr = Array::New(env()->isolate(), count);
Local<Object> buf;
for (size_t i = 0; i < count; i++) {
buf = Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked();
bufs_arr->Set(i, buf);
}
Local<Value> argv[] = {
w->object(),
bufs_arr
};
TryCatch try_catch(env()->isolate());
Local<Value> value;
int value_int = UV_EPROTO;
if (!MakeCallback(env()->onwrite_string(),
arraysize(argv),
argv).ToLocal(&value) ||
!value->Int32Value(env()->context()).To(&value_int)) {
if (!try_catch.HasTerminated())
FatalException(env()->isolate(), try_catch);
}
return value_int;
}
|
CWE-416
| 18,665
|
int LibuvStreamWrap::DoWrite(WriteWrap* req_wrap,
uv_buf_t* bufs,
size_t count,
uv_stream_t* send_handle) {
LibuvWriteWrap* w = static_cast<LibuvWriteWrap*>(req_wrap);
int r;
if (send_handle == nullptr) {
r = w->Dispatch(uv_write, stream(), bufs, count, AfterUvWrite);
} else {
r = w->Dispatch(uv_write2,
stream(),
bufs,
count,
send_handle,
AfterUvWrite);
}
if (!r) {
size_t bytes = 0;
for (size_t i = 0; i < count; i++)
bytes += bufs[i].len;
if (stream()->type == UV_TCP) {
NODE_COUNT_NET_BYTES_SENT(bytes);
} else if (stream()->type == UV_NAMED_PIPE) {
NODE_COUNT_PIPE_BYTES_SENT(bytes);
}
}
return r;
}
|
CWE-416
| 18,666
|
inline StreamWriteResult StreamBase::Write(
uv_buf_t* bufs,
size_t count,
uv_stream_t* send_handle,
v8::Local<v8::Object> req_wrap_obj) {
Environment* env = stream_env();
int err;
size_t total_bytes = 0;
for (size_t i = 0; i < count; ++i)
total_bytes += bufs[i].len;
bytes_written_ += total_bytes;
if (send_handle == nullptr) {
err = DoTryWrite(&bufs, &count);
if (err != 0 || count == 0) {
return StreamWriteResult { false, err, nullptr, total_bytes };
}
}
HandleScope handle_scope(env->isolate());
if (req_wrap_obj.IsEmpty()) {
req_wrap_obj =
env->write_wrap_template()
->NewInstance(env->context()).ToLocalChecked();
StreamReq::ResetObject(req_wrap_obj);
}
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap());
WriteWrap* req_wrap = CreateWriteWrap(req_wrap_obj);
err = DoWrite(req_wrap, bufs, count, send_handle);
bool async = err == 0;
if (!async) {
req_wrap->Dispose();
req_wrap = nullptr;
}
const char* msg = Error();
if (msg != nullptr) {
req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg));
ClearError();
}
return StreamWriteResult { async, err, req_wrap, total_bytes };
}
|
CWE-416
| 18,667
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.