75     unsigned v = le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
 
   81     unsigned v = le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
 
   87     av_alias64 i = { .u64 = le ? bytestream2_get_le64(gb) : bytestream2_get_be64(gb)};
 
   95         return bytestream2_get_byte(gb);
 
  115 #define RET_GEOKEY(TYPE, array, element)\ 
  116     if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\ 
  117         key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\ 
  118         return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element; 
  163 #define RET_GEOKEY_VAL(TYPE, array)\ 
  164     if (val >= TIFF_##TYPE##_OFFSET &&\ 
  165         val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\ 
  166         return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]); 
  218         snprintf(ap, 14, 
"Unknown-%d", val);
 
  226     uint64_t component_len;
 
  227     if (!sep) sep = 
", ";
 
  228     component_len = 15LL + strlen(sep);
 
  229     if (count >= (INT_MAX - 1)/component_len)
 
  231     ap = 
av_malloc(component_len * count + 1);
 
  236     for (i = 0; i < 
count; i++) {
 
  237         unsigned l = 
snprintf(ap, component_len, 
"%f%s", dp[i], sep);
 
  238         if(l >= component_len) {
 
  244     ap0[strlen(ap0) - strlen(sep)] = 
'\0';
 
  252     uint64_t component_len;
 
  253     if (!sep) sep = 
", ";
 
  254     component_len = 7LL + strlen(sep);
 
  255     if (count >= (INT_MAX - 1)/component_len)
 
  257     ap = 
av_malloc(component_len * count + 1);
 
  262     for (i = 0; i < 
count; i++) {
 
  263         unsigned l = 
snprintf(ap, component_len, 
"%d%s", sp[i], sep);
 
  264         if (l >= component_len) {
 
  270     ap0[strlen(ap0) - strlen(sep)] = 
'\0';
 
  275                                 const char *
name, 
const char *sep,
 
  282     if (count >= INT_MAX / 
sizeof(int64_t) || count <= 0)
 
  291     for (i = 0; i < 
count; i++)
 
  308     if (count >= INT_MAX / 
sizeof(int16_t) || count <= 0)
 
  317     for (i = 0; i < 
count; i++)
 
  363         while (--width >= 0) {
 
  364             dst[(width+
offset)*8+7] = (usePtr ? src[width] : c)      & 0x1;
 
  365             dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
 
  366             dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
 
  367             dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
 
  368             dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
 
  369             dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
 
  370             dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
 
  371             dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
 
  375         while (--width >= 0) {
 
  376             dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
 
  377             dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
 
  378             dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
 
  379             dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
 
  383         while (--width >= 0) {
 
  384             dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
 
  385             dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
 
  390             memcpy(dst + offset, src, width);
 
  392             memset(dst + offset, c, width);
 
  404     for (i = 0; i < 
size; i++)
 
  414     z_stream zstream = { 0 };
 
  417     zstream.next_in   = (
uint8_t *)src;
 
  418     zstream.avail_in  = 
size;
 
  419     zstream.next_out  = dst;
 
  420     zstream.avail_out = *
len;
 
  421     zret              = inflateInit(&zstream);
 
  426     zret = inflate(&zstream, Z_SYNC_FLUSH);
 
  427     inflateEnd(&zstream);
 
  428     *len = zstream.total_out;
 
  429     return zret == Z_STREAM_END ? Z_OK : zret;
 
  434                             int width, 
int lines)
 
  437     unsigned long outlen;
 
  439     outlen = width * lines;
 
  450     ret = tiff_uncompress(zbuf, &outlen, src, size);
 
  453                "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
 
  454                (
unsigned long)width * lines, ret);
 
  459     for (line = 0; line < lines; line++) {
 
  463             memcpy(dst, src, width);
 
  475                            const uint8_t *src, 
int size, 
int width, 
int lines)
 
  484                "Error allocating temporary buffer\n");
 
  493         memcpy(src2, src, size);
 
  495         for (i = 0; i < 
size; i++)
 
  502         for (line = 0; line < lines; line++) {
 
  511                              const uint8_t *src, 
int size, 
int lines)
 
  513     int c, line, pixels, code, 
ret;
 
  515     int width           = ((s->
width * s->
bpp) + 7) >> 3;
 
  525         return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
 
  528                "zlib support not enabled, " 
  529                "deflate compression not supported\n");
 
  539         if (size > 1 && !src[0] && (src[1]&1)) {
 
  552     for (line = 0; line < lines; line++) {
 
  553         if (src - ssrc > size) {
 
  559             if (ssrc + size - src < width)
 
  563                                 dst, 1, src, 0, width, 0);
 
  566                 for (i = 0; i < 
width; i++)
 
  572             for (pixels = 0; pixels < 
width;) {
 
  573                 if (ssrc + size - src < 2) {
 
  580                     if (pixels + code > width ||
 
  581                         ssrc + size - src < code) {
 
  583                                "Copy went out of bounds\n");
 
  587                                     dst, 1, src, 0, code, pixels);
 
  590                 } 
else if (code != -128) { 
 
  592                     if (pixels + code > width) {
 
  594                                "Run went out of bounds\n");
 
  599                                     dst, 0, NULL, c, code, pixels);
 
  605                 for (i = 0; i < 
width; i++)
 
  611             if (pixels < width) {
 
  673                "This format is not supported (bpp=%d, bppcount=%d)\n",
 
  689             pal = (uint32_t *) frame->
data[1];
 
  690             for (i = 0; i < 1<<s->
bpp; i++)
 
  691                 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
 
  700     int i, j, k, pos, 
start;
 
  737         if (count <= 4 && 
type_sizes[type] * count <= 4)
 
  754                    "This format is not supported (bpp=%d, %d components)\n",
 
  763                 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
 
  764                          ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
 
  771                 for (i = 0; i < 
count; i++)
 
  782                    "Samples per pixel requires a single value, many provided\n");
 
  787                    "Samples per pixel %d is too large\n", value);
 
  826         if (type == 
TIFF_LONG && value == UINT_MAX)
 
  830                    "Incorrect value of rows per strip\n");
 
  847                    "Tag referencing position outside the image\n");
 
  863                    "Tag referencing position outside the image\n");
 
  895         if (value < 1 || value > 2) {
 
  897                    "Unknown FillOrder value %d, trying default one\n", value);
 
  908         for (k = 2; k >= 0; k--) {
 
  909             for (i = 0; i < count / 3; i++) {
 
  911                     pal[i] = 0xFF
U << 24;
 
  929 #define ADD_METADATA(count, name, sep)\ 
  930     if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\ 
  931         av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\ 
  973         if (count >= INT_MAX / 
sizeof(int64_t))
 
  982         for (i = 0; i < 
count; i++)
 
 1063                    "Unknown or unsupported tag %d/0X%0X\n",
 
 1078     int id, 
le, 
ret, plane, planes;
 
 1079     int i, j, entries, 
stride;
 
 1080     unsigned soff, ssize;
 
 1088     if (avpkt->
size < 8)
 
 1090     id   = bytestream2_get_le16u(&s->
gb);
 
 1093     else if (
id == 0x4D4D)
 
 1111                "The answer to life, universe and everything is not correct!\n");
 
 1118     if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
 
 1126     for (i = 0; i < entries; i++) {
 
 1178     for (plane = 0; plane < planes; plane++) {
 
 1180         dst    = p->
data[plane];
 
 1181     for (i = 0; i < s->
height; i += s->
rps) {
 
 1192         if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
 
 1205         dst   = p->
data[plane];
 
 1209         ssize = s->
width * soff;
 
 1214             for (i = 0; i < s->
height; i++) {
 
 1215                 for (j = soff; j < ssize; j += 2)
 
 1223             for (i = 0; i < s->
height; i++) {
 
 1224                 for (j = soff; j < ssize; j += 2)
 
 1229             for (i = 0; i < s->
height; i++) {
 
 1230                 for (j = soff; j < ssize; j++)
 
 1231                     dst[j] += dst[j - soff];
 
 1238         dst = p->
data[plane];
 
 1239         for (i = 0; i < s->
height; i++) {
 
 1240             for (j = 0; j < p->
linesize[plane]; j++)