range_shift, uint16_t);
rc = read (fd, subtable, offset);
- if (rc < offset)
+ if (rc == -1 || rc < offset)
{
- if (rc >= sizeof (uint32_t))
+ if (rc != -1 && rc >= sizeof (uint32_t))
{
/* Detect a TTC file. In that case, the first long will be
``ttcf''. */
rc = read (fd, subtable->subtables, subtable_size);
- if (rc < offset)
+ if (rc == -1 || rc < offset)
{
xfree (subtable);
return NULL;
language));
rc = read (fd, &format0->language, wanted_size);
- if (rc < wanted_size)
+ if (rc == -1 || rc < wanted_size)
{
xfree (format0);
return (struct sfnt_cmap_format_0 *) -1;
/* Read the part before the variable length data. */
min_bytes -= offsetof (struct sfnt_cmap_format_2, language);
rc = read (fd, &format2->language, min_bytes);
- if (rc < min_bytes)
+ if (rc == -1 || rc < min_bytes)
{
xfree (format2);
return (struct sfnt_cmap_format_2 *) -1;
- SFNT_ENDOF (struct sfnt_cmap_format_2,
sub_header_keys, uint16_t[256]));
rc = read (fd, format2 + 1, min_bytes);
- if (rc < min_bytes)
+ if (rc == -1 || rc < min_bytes)
{
xfree (format2);
return (struct sfnt_cmap_format_2 *) -1;
/* Read the initial data. */
min_bytes -= offsetof (struct sfnt_cmap_format_4, language);
rc = read (fd, &format4->language, min_bytes);
- if (rc < min_bytes)
+ if (rc == -1 || rc < min_bytes)
{
xfree (format4);
return (struct sfnt_cmap_format_4 *) -1;
/* Read the rest of the bytes to the end of format4. */
rc = read (fd, format4 + 1, bytes_minus_format4);
- if (rc < bytes_minus_format4)
+ if (rc == -1 || rc < bytes_minus_format4)
{
xfree (format4);
return (struct sfnt_cmap_format_4 *) -1;
/* Read the fixed size data. */
min_size -= offsetof (struct sfnt_cmap_format_6, language);
rc = read (fd, &format6->language, min_size);
- if (rc < min_size)
+ if (rc == -1 || rc < min_size)
{
xfree (format6);
return (struct sfnt_cmap_format_6 *) -1;
rc = read (fd, format6 + 1,
(format6->entry_count
* sizeof *format6->glyph_index_array));
- if (rc < format6->entry_count * sizeof *format6->glyph_index_array)
+ if (rc == -1 || (rc < (format6->entry_count
+ * sizeof *format6->glyph_index_array)))
{
xfree (format6);
return (struct sfnt_cmap_format_6 *) -1;
uint32_t length, i;
/* Read the 32-bit length field. */
- if (read (fd, &length, sizeof (length)) < sizeof (length))
+ if (read (fd, &length, sizeof length) < (int) sizeof length)
return (struct sfnt_cmap_format_8 *) -1;
/* Swap the 32-bit length field. */
/* Read the fixed length data. */
min_size -= offsetof (struct sfnt_cmap_format_8, language);
rc = read (fd, &format8->language, min_size);
- if (rc < min_size)
+ if (rc == -1 || rc < min_size)
{
xfree (format8);
return (struct sfnt_cmap_format_8 *) -1;
/* Now read the variable length data. */
rc = read (fd, format8 + 1, temp);
- if (rc < temp)
+ if (rc == -1 || rc < temp)
{
xfree (format8);
return (struct sfnt_cmap_format_8 *) -1;
uint32_t length, i;
/* Read the 32-bit length field. */
- if (read (fd, &length, sizeof (length)) < sizeof (length))
+ if (read (fd, &length, sizeof length) < (int) sizeof length)
return (struct sfnt_cmap_format_12 *) -1;
/* Swap the 32-bit length field. */
/* Read the fixed length data. */
min_size -= offsetof (struct sfnt_cmap_format_12, language);
rc = read (fd, &format12->language, min_size);
- if (rc < min_size)
+ if (rc == -1 || rc < min_size)
{
xfree (format12);
return (struct sfnt_cmap_format_12 *) -1;
/* Now read the variable length data. */
rc = read (fd, format12 + 1, temp);
- if (rc < temp)
+ if (rc == -1 || rc < temp)
{
xfree (format12);
return (struct sfnt_cmap_format_12 *) -1;
uint32_t buffer1[2];
size_t size, temp;
char buffer[3 + 4 + 4];
- int i;
+ uint32_t i;
/* Read the length field and number of variation selector
records. */
- if (read (fd, buffer1, sizeof buffer1) < sizeof buffer1)
+ if (read (fd, buffer1, sizeof buffer1) < (int) sizeof buffer1)
return NULL;
length = buffer1[0];
for (i = 0; i < num_records; ++i)
{
- if (read (fd, buffer, sizeof buffer) < sizeof buffer)
+ if (read (fd, buffer, sizeof buffer) < (int) sizeof buffer)
{
xfree (format14);
return NULL;
return (struct sfnt_cmap_encoding_subtable_data *) -1;
if (read (fd, &header.format, sizeof header.format)
- < sizeof header.format)
+ < (int) sizeof header.format)
return (struct sfnt_cmap_encoding_subtable_data *) -1;
sfnt_swap16 (&header.format);
if (header.format != 14)
{
if (read (fd, &header.length, sizeof header.length)
- < sizeof header.length)
+ < (int) sizeof header.length)
return (struct sfnt_cmap_encoding_subtable_data *) -1;
sfnt_swap16 (&header.length);
cmap = xmalloc (sizeof *cmap);
rc = read (fd, cmap, sizeof *cmap);
- if (rc < sizeof *cmap)
+ if (rc < (int) sizeof *cmap)
{
xfree (cmap);
return NULL;
/* Read the common part of the new subtable. */
rc = read (fd, &(*subtables)[i], sizeof (*subtables)[i]);
- if (rc < sizeof (*subtables)[i])
+ if (rc < (int) sizeof (*subtables)[i])
{
xfree (cmap);
xfree (*subtables);
head = xmalloc (sizeof *head);
rc = read (fd, head, sizeof *head);
- if (rc < sizeof *head)
+ if (rc < (int) sizeof *head)
{
xfree (head);
return NULL;
hhea = xmalloc (sizeof *hhea);
rc = read (fd, hhea, sizeof *hhea);
- if (rc < sizeof *hhea)
+ if (rc < (int) sizeof *hhea)
{
xfree (hhea);
return NULL;
size = MIN (directory->length, sizeof *maxp);
rc = read (fd, maxp, size);
- if (rc < size)
+ if (rc == -1 || rc < size)
{
xfree (maxp);
return NULL;
/* Read the glyph data. */
rc = read (fd, glyf->glyphs, glyf->size);
- if (rc < glyf->size)
+ if (rc == -1 || rc < glyf->size)
{
xfree (glyf);
return NULL;
/* Read into hmtx + 1. */
rc = read (fd, hmtx + 1, size);
- if (rc < size)
+ if (rc == -1 || rc < size)
{
xfree (hmtx);
return NULL;
/* Read the fixed length data. */
rc = read (fd, name, required);
- if (rc < required)
+ if (rc == -1 || rc < required)
{
xfree (name);
return NULL;
rc = read (fd, name->name_records,
(name->count
* sizeof *name->name_records));
- if (rc < (name->count
- * sizeof *name->name_records))
+ if (rc == -1 || (rc < (name->count
+ * sizeof *name->name_records)))
{
xfree (name);
return NULL;
name->data = (unsigned char *) (name->name_records
+ name->count);
rc = read (fd, name->data, required);
- if (rc < required)
+ if (rc == -1 || rc < required)
{
xfree (name);
return NULL;
/* Read the header. */
rc = read (fd, meta, required);
- if (rc < required)
+ if (rc == -1 || rc < required)
{
xfree (meta);
return NULL;
size = SFNT_ENDOF (struct sfnt_ttc_header, num_fonts,
uint32_t);
rc = read (fd, ttc, size);
- if (rc < size)
+ if (rc == -1 || rc < size)
{
xfree (ttc);
return NULL;
ttc = xrealloc (ttc, sizeof *ttc + size);
ttc->offset_table = (uint32_t *) (ttc + 1);
rc = read (fd, ttc->offset_table, size);
- if (rc < size)
+ if (rc == -1 || rc < size)
{
xfree (ttc);
return NULL;
uint32_t)
- offsetof (struct sfnt_ttc_header, ul_dsig_tag));
rc = read (fd, &ttc->ul_dsig_offset, size);
- if (rc < size)
+ if (rc == -1 || rc < size)
{
xfree (ttc);
return NULL;
{
struct sfnt_default_uvs_table *uvs;
uint32_t num_ranges, i, j;
- size_t size, temp;
+ ssize_t size, temp;
char data[512];
/* First, seek to the given offset. */
/* Next, read the number of ranges present. */
- if (read (fd, &num_ranges, sizeof num_ranges) != sizeof num_ranges)
+ if (read (fd, &num_ranges, sizeof num_ranges)
+ != (int) sizeof num_ranges)
return NULL;
/* Swap the number of ranges present. */
{
struct sfnt_nondefault_uvs_table *uvs;
uint32_t num_mappings, i, j;
- size_t size, temp;
+ ssize_t size, temp;
char data[500];
/* First, seek to the given offset. */
/* Read the fvar table header. */
buffer = NULL;
rc = read (fd, fvar, min_bytes);
- if (rc != min_bytes)
+ if (rc == -1 || rc != min_bytes)
goto bail;
/* Swap what was read. */
goto bail;
rc = read (fd, fvar->axis, sizeof *fvar->axis * fvar->axis_count);
- if (rc != sizeof *fvar->axis * fvar->axis_count)
+ if (rc == -1 || rc != sizeof *fvar->axis * fvar->axis_count)
goto bail;
/* Swap each axis. */
/* Read the gvar table header. */
rc = read (fd, gvar, min_bytes);
- if (rc != min_bytes)
+ if (rc == -1 || rc != min_bytes)
goto bail;
/* Swap what was read. */
{
gvar->u.offset_long = (uint32_t *) (gvar + 1);
rc = read (fd, gvar->u.offset_long, off_size);
- if (rc != off_size)
+ if (rc == -1 || rc != off_size)
goto bail;
for (i = 0; i <= gvar->glyph_count; ++i)
if (lseek (fd, offset, SEEK_SET) != offset)
goto bail;
- if (read (fd, gvar->global_coords, coordinate_size)
- != coordinate_size)
+ rc = read (fd, gvar->global_coords, coordinate_size);
+
+ if (rc == -1 || rc != coordinate_size)
goto bail;
for (i = 0; i < coordinate_size / sizeof *gvar->global_coords; ++i)
if (lseek (fd, offset, SEEK_SET) != offset)
goto bail;
- if (read (fd, gvar->glyph_variation_data,
- gvar->data_size) != gvar->data_size)
+ rc = read (fd, gvar->glyph_variation_data, gvar->data_size);
+
+ if (rc == -1 || rc != gvar->data_size)
goto bail;
}
/* Read the avar table header. */
rc = read (fd, avar, min_size);
- if (rc != min_size)
+ if (rc == -1 || rc != min_size)
goto bail;
/* Swap what was read. */
size = directory->length - min_size;
buffer = xmalloc (size);
rc = read (fd, buffer, size);
- if (rc != size)
+ if (rc == -1 || rc != size)
goto bail1;
/* Swap each word. */
size = directory->length - min_size;
buffer = xmalloc (size);
rc = read (fd, buffer, size);
- if (rc != size)
+ if (rc == -1 || rc != size)
goto bail;
/* Now figure out how large cvar must be by reading the tuples. */
unsigned char[10]);
rc = read (fd, OS_2, wanted);
- if (rc != wanted)
+ if (rc == -1 || rc != wanted)
{
xfree (OS_2);
return NULL;
- offsetof (struct sfnt_OS_2_table, ul_unicode_range));
rc = read (fd, &OS_2->ul_unicode_range, wanted);
- if (rc != wanted)
+ if (rc == -1 || rc != wanted)
{
xfree (OS_2);
return NULL;