Project import generated by Copybara.

GitOrigin-RevId: 4e2c56f1a185ffafed747eb9f5206257b0f5f3a7
diff --git a/Android.bp b/Android.bp
deleted file mode 100644
index c5bc307..0000000
--- a/Android.bp
+++ /dev/null
@@ -1,124 +0,0 @@
-//
-// Copyright (C) 2013 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-// WARNING: this makefile builds a shared library. Do not ever make it build
-// a static library or otherwise statically link libexif with your code.
-package {
-    default_applicable_licenses: ["external_libexif_license"],
-}
-
-// Added automatically by a large-scale-change that took the approach of
-// 'apply every license found to every target'. While this makes sure we respect
-// every license restriction, it may not be entirely correct.
-//
-// e.g. GPL in an MIT project might only apply to the contrib/ directory.
-//
-// Please consider splitting the single license below into multiple licenses,
-// taking care not to lose any license_kind information, and overriding the
-// default license using the 'licenses: [...]' property on targets as needed.
-//
-// For unused files, consider creating a 'fileGroup' with "//visibility:private"
-// to attach the license to, and including a comment whether the files may be
-// used in the current project.
-//
-// large-scale-change included anything that looked like it might be a license
-// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
-//
-// Please consider removing redundant or irrelevant files from 'license_text:'.
-// See: http://go/android-license-faq
-license {
-    name: "external_libexif_license",
-    visibility: [":__subpackages__"],
-    license_kinds: [
-        "SPDX-license-identifier-Apache-2.0",
-        "SPDX-license-identifier-BSD",
-        "SPDX-license-identifier-FSFAP",
-        "SPDX-license-identifier-GPL",
-        "SPDX-license-identifier-LGPL",
-        "SPDX-license-identifier-LGPL-2.1",
-        "SPDX-license-identifier-LGPL-3.0",
-        "SPDX-license-identifier-MIT",
-        "legacy_notice",
-        "legacy_permissive",
-        "legacy_unencumbered",
-    ],
-    license_text: [
-        "COPYING",
-        "NOTICE",
-    ],
-}
-
-cc_library_shared {
-    name: "libexif",
-    host_supported: true,
-    vendor_available: true,
-    vndk: {
-        enabled: true,
-    },
-
-    srcs: [
-        "libexif/exif-byte-order.c",
-        "libexif/exif-content.c",
-        "libexif/exif-data.c",
-        "libexif/exif-entry.c",
-        "libexif/exif-format.c",
-        "libexif/exif-ifd.c",
-        "libexif/exif-loader.c",
-        "libexif/exif-log.c",
-        "libexif/exif-mem.c",
-        "libexif/exif-mnote-data.c",
-        "libexif/exif-tag.c",
-        "libexif/exif-utils.c",
-        "libexif/canon/exif-mnote-data-canon.c",
-        "libexif/canon/mnote-canon-entry.c",
-        "libexif/canon/mnote-canon-tag.c",
-        "libexif/olympus/exif-mnote-data-olympus.c",
-        "libexif/olympus/mnote-olympus-tag.c",
-        "libexif/olympus/mnote-olympus-entry.c",
-        "libexif/fuji/exif-mnote-data-fuji.c",
-        "libexif/fuji/mnote-fuji-entry.c",
-        "libexif/fuji/mnote-fuji-tag.c",
-        "libexif/pentax/exif-mnote-data-pentax.c",
-        "libexif/pentax/mnote-pentax-entry.c",
-        "libexif/pentax/mnote-pentax-tag.c",
-    ],
-
-    shared_libs: [
-        "liblog",
-    ],
-
-    export_include_dirs: ["."],
-
-    cflags: [
-        "-ftrapv",
-
-        // TODO(b/27347470): Disable the following warnings.
-        "-Wno-conversion",
-        "-Wno-unused-parameter",
-        "-Wno-missing-field-initializers",
-        "-Wno-switch",
-        "-Wno-absolute-value",
-        "-Werror",
-    ],
-
-    sanitize: {
-        integer_overflow: true,
-        blocklist: "libexif_blocklist.txt",
-    },
-}
-
-// WARNING: this makefile builds a shared library. Do not ever make it build
-// a static library or otherwise statically link libexif with your code.
diff --git a/MODULE_LICENSE_LGPL b/MODULE_LICENSE_LGPL
deleted file mode 100644
index e69de29..0000000
--- a/MODULE_LICENSE_LGPL
+++ /dev/null
diff --git a/NOTICE b/NOTICE
index 75657f7..223ede7 100644
--- a/NOTICE
+++ b/NOTICE
@@ -2,7 +2,7 @@
 		       Version 2.1, February 1999
 
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
@@ -146,7 +146,7 @@
 on the Library (independent of the use of the Library in a tool for
 writing it).  Whether that is true depends on what the Library does
 and what the program that uses the Library does.
-
+  
   1. You may copy and distribute verbatim copies of the Library's
 complete source code as you receive it, in any medium, provided that
 you conspicuously and appropriately publish on each copy an
@@ -476,7 +476,7 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2 of the License, or (at your option) any later version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -485,7 +485,7 @@
 
     You should have received a copy of the GNU Lesser General Public
     License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 Also add information on how to contact you by electronic and paper mail.
 
@@ -501,3 +501,4 @@
 
 That's all there is to it!
 
+
diff --git a/OWNERS b/OWNERS
deleted file mode 100644
index 139b26e..0000000
--- a/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
-eliribble@google.com
-allenlintwo@google.com
-jlevasseur@google.com
diff --git a/README.android b/README.android
deleted file mode 100644
index e207a69..0000000
--- a/README.android
+++ /dev/null
@@ -1,5 +0,0 @@
-Note:
-- libexif is LGPLv2.1
-- do not statically link to it
-- do not upgrade to LGPLv3
-
diff --git a/README.version b/README.version
deleted file mode 100644
index 1f82982..0000000
--- a/README.version
+++ /dev/null
@@ -1,3 +0,0 @@
-URL: http://sourceforge.net/projects/libexif/files/libexif/0.6.21/libexif-0.6.21.tar.gz/download
-Version: 0.6.21
-BugComponent: 1344
diff --git a/config.h b/config.h
index cdb6f04..c51c43c 100644
--- a/config.h
+++ b/config.h
@@ -3,11 +3,11 @@
 
 /* Define to 1 if translation of program messages to the user's native
    language is requested. */
-/* #undef ENABLE_NLS */
+#define ENABLE_NLS 1
 
 /* Define if the GNU dcgettext() function is already present or preinstalled.
    */
-/* #undef HAVE_DCGETTEXT */
+/* #iundef HAVE_DCGETTEXT */
 
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #define HAVE_DLFCN_H 1
@@ -15,11 +15,8 @@
 /* Define if the GNU gettext() function is already present or preinstalled. */
 /* #undef HAVE_GETTEXT */
 
-// needed because code calls bindtextdomain macro even when not using gettext
-#define GETTEXT_PACKAGE 0
-
 /* Define if you have the iconv() function. */
-#define HAVE_ICONV 1
+/* #undef HAVE_ICONV */
 
 /* Define to 1 if you have the <inttypes.h> header file. */
 #define HAVE_INTTYPES_H 1
diff --git a/libexif/canon/exif-mnote-data-canon.c b/libexif/canon/exif-mnote-data-canon.c
index acf88ab..eb53598 100644
--- a/libexif/canon/exif-mnote-data-canon.c
+++ b/libexif/canon/exif-mnote-data-canon.c
@@ -267,7 +267,7 @@
 			if ((dataofs + s < s) || (dataofs + s < dataofs) || (dataofs + s > buf_size)) {
 				exif_log (ne->log, EXIF_LOG_CODE_DEBUG,
 					"ExifMnoteCanon",
-					"Tag data past end of buffer (%zu > %u)",
+					"Tag data past end of buffer (%u > %u)",
 					dataofs + s, buf_size);
 				continue;
 			}
diff --git a/libexif/exif-data.c b/libexif/exif-data.c
index 5a7763b..67df4db 100644
--- a/libexif/exif-data.c
+++ b/libexif/exif-data.c
@@ -35,11 +35,9 @@
 #include <libexif/olympus/exif-mnote-data-olympus.h>
 #include <libexif/pentax/exif-mnote-data-pentax.h>
 
-#include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <limits.h>
 
 #undef JPEG_MARKER_SOI
 #define JPEG_MARKER_SOI  0xd8
@@ -193,12 +191,9 @@
 		doff = offset + 8;
 
 	/* Sanity checks */
-	int64_t doff64 = doff;
-	int64_t s64 = s;
-	if (doff64 + s64 > (int64_t) size) {
+	if ((doff + s < doff) || (doff + s < s) || (doff + s > size)) {
 		exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
-				  "Tag data past end of buffer (%" PRId64 " > %u)",
-				  doff64+s64, size);
+				  "Tag data past end of buffer (%u > %u)", doff+s, size);	
 		return 0;
 	}
 
@@ -300,9 +295,7 @@
 	/* Write the data. Fill unneeded bytes with 0. Do not crash with
 	 * e->data is NULL */
 	if (e->data) {
-		unsigned int len = s;
-		if (e->size < s) len = e->size;
-		memcpy (*d + 6 + doff, e->data, len);
+		memcpy (*d + 6 + doff, e->data, s);
 	} else {
 		memset (*d + 6 + doff, 0, s);
 	}
@@ -315,10 +308,7 @@
 			       unsigned int ds, ExifLong o, ExifLong s)
 {
 	/* Sanity checks */
-	uint64_t o64 = (uint64_t) o;
-	uint64_t s64 = (uint64_t) s;
-	uint64_t ds64 = (uint64_t) ds;
-	if ((o64 + s64) > ds64) {
+	if ((o + s < o) || (o + s < s) || (o + s > ds) || (o > ds)) {
 		exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
 			  "Bogus thumbnail offset (%u) or size (%u).",
 			  o, s);
@@ -389,9 +379,9 @@
 	}
 
 	/* Read the number of entries */
-	if ((offset > UINT_MAX - 2) || (offset + 2 > ds)) {
+	if ((offset + 2 < offset) || (offset + 2 < 2) || (offset + 2 > ds)) {
 		exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData",
-			  "Tag data past end of buffer (%u + 2 > %u)", offset, ds);
+			  "Tag data past end of buffer (%u > %u)", offset+2, ds);
 		return;
 	}
 	n = exif_get_short (d + offset, data->priv->order);
@@ -914,7 +904,7 @@
 		  "IFD 0 at %i.", (int) offset);
 
 	/* Sanity check the offset, being careful about overflow */
-	if (offset > ds || (uint64_t)offset + 6 + 2 > ds)
+	if (offset > ds || offset + 6 + 2 > ds)
 		return;
 
 	/* Parse the actual exif data (usually offset 14 from start) */
@@ -922,7 +912,7 @@
 
 	/* IFD 1 offset */
 	n = exif_get_short (d + 6 + offset, data->priv->order);
-	if ((uint64_t)offset + 6 + 2 + 12 * n + 4 > ds)
+	if (offset + 6 + 2 + 12 * n + 4 > ds)
 		return;
 
 	offset = exif_get_long (d + 6 + offset + 2 + 12 * n, data->priv->order);
@@ -931,7 +921,7 @@
 			  "IFD 1 at %i.", (int) offset);
 
 		/* Sanity check. */
-		if (offset > ds || (uint64_t)offset + 6 > ds) {
+		if (offset > ds || offset + 6 > ds) {
 			exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA,
 				  "ExifData", "Bogus offset of IFD1.");
 		} else {
diff --git a/libexif/exif-entry.c b/libexif/exif-entry.c
index 1fb2931..54a90a2 100644
--- a/libexif/exif-entry.c
+++ b/libexif/exif-entry.c
@@ -31,8 +31,6 @@
 #include <string.h>
 #include <time.h>
 #include <math.h>
-#include <limits.h>
-#include <log/log.h>
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
@@ -991,7 +989,7 @@
 				int editor_ofs = tagdata - e->data;
 				int remaining = e->size - editor_ofs;
 				if (match_repeated_char(tagdata, ' ', remaining)) {
-					strncat (val, (const char*)tagdata, MIN (maxlen - strlen (val), (size_t)remaining));
+					strncat (val, (const char*)tagdata, MIN (maxlen - strlen (val), remaining));
 					++k;
 				}
 			}
@@ -1045,12 +1043,12 @@
 		d = 0.;
 		entry = exif_content_get_entry (
 			e->parent->parent->ifd[EXIF_IFD_0], EXIF_TAG_MAKE);
-		if (entry && entry->data && (entry->size > 7) &&
+		if (entry && entry->data &&
 		    !strncmp ((char *)entry->data, "Minolta", 7)) {
 			entry = exif_content_get_entry (
 					e->parent->parent->ifd[EXIF_IFD_0],
 					EXIF_TAG_MODEL);
-			if (entry && entry->data && (entry->size > 8)) {
+			if (entry && entry->data) {
 				if (!strncmp ((char *)entry->data, "DiMAGE 7", 8))
 					d = 3.9;
 				else if (!strncmp ((char *)entry->data, "DiMAGE 5", 8))
@@ -1378,10 +1376,7 @@
 	case EXIF_TAG_XP_SUBJECT:
 	{
 		/* Sanity check the size to prevent overflow */
-		if (e->size > UINT_MAX - sizeof(unsigned short)) {
-			snprintf (val, maxlen, "Value overflow in EXIF_TAG_XP_SUBJECT");
-			break;
-		}
+		if (e->size+sizeof(unsigned short) < e->size) break;
 
 		/* The tag may not be U+0000-terminated , so make a local
 		   U+0000-terminated copy before converting it */
diff --git a/libexif/exif-loader.c b/libexif/exif-loader.c
index 7aebf1e..317b86b 100644
--- a/libexif/exif-loader.c
+++ b/libexif/exif-loader.c
@@ -225,7 +225,7 @@
 		break;
 	}
 
-	for (i = 0; i < sizeof (eld->b); i++) {
+	for (i = 0; i < sizeof (eld->b); i++)
 		switch (eld->state) {
 		case EL_EXIF_FOUND:
 			if (!exif_loader_copy (eld, eld->b + i,
@@ -233,19 +233,9 @@
 				return 0;
 			return exif_loader_copy (eld, buf, len);
 		case EL_SKIP_BYTES:
-			switch (eld->size) {
-                            case 0:
-			        eld->state = EL_READ;
-				i--;   // reprocess this byte
-				break;
-                            case 1:
-                                eld->size = 0;
-			        eld->state = EL_READ;
-				break;
-                            default:
-                                eld->size--;
-				break;
-			}
+			eld->size--;
+			if (!eld->size) 
+				eld->state = EL_READ;
 			break;
 
 		case EL_READ_SIZE_BYTE_24:
@@ -265,20 +255,12 @@
 			switch (eld->data_format) {
 			case EL_DATA_FORMAT_JPEG:
 				eld->state = EL_SKIP_BYTES;
-				if (eld->size < 2) {
-				    // Actually it's malformed...
-				    eld->size = 0;
-				} else
-				    eld->size -= 2;
+				eld->size -= 2;
 				break;
 			case EL_DATA_FORMAT_FUJI_RAW:
 				eld->data_format = EL_DATA_FORMAT_EXIF;
 				eld->state = EL_SKIP_BYTES;
-				if (eld->size < 86) {
-				    // Actually it's malformed...
-				    eld->size = 0;
-				} else
-				    eld->size -= 86;	// and put this in an else
+				eld->size -= 86;
 				break;
 			case EL_DATA_FORMAT_EXIF:
 				eld->state = EL_EXIF_FOUND;
@@ -322,7 +304,6 @@
 				return 0;
 			}
 		}
-	}
 
 	/*
 	 * If we reach this point, the buffer has not been big enough
diff --git a/libexif/fuji/exif-mnote-data-fuji.c b/libexif/fuji/exif-mnote-data-fuji.c
index a9949e1..9514654 100644
--- a/libexif/fuji/exif-mnote-data-fuji.c
+++ b/libexif/fuji/exif-mnote-data-fuji.c
@@ -225,7 +225,7 @@
 				(dataofs + s >= buf_size)) {
 				exif_log (en->log, EXIF_LOG_CODE_CORRUPT_DATA,
 						  "ExifMnoteDataFuji", "Tag data past end of "
-					  "buffer (%zu >= %u)", dataofs + s, buf_size);
+					  "buffer (%u >= %u)", dataofs + s, buf_size);
 				continue;
 			}
 
diff --git a/libexif/olympus/exif-mnote-data-olympus.c b/libexif/olympus/exif-mnote-data-olympus.c
index f4ccbb0..099671d 100644
--- a/libexif/olympus/exif-mnote-data-olympus.c
+++ b/libexif/olympus/exif-mnote-data-olympus.c
@@ -482,7 +482,7 @@
 			    (dataofs + s > buf_size)) {
 				exif_log (en->log, EXIF_LOG_CODE_DEBUG,
 					  "ExifMnoteOlympus",
-					  "Tag data past end of buffer (%zu > %u)",
+					  "Tag data past end of buffer (%u > %u)",
 					  dataofs + s, buf_size);
 				continue;
 			}
diff --git a/libexif/pentax/exif-mnote-data-pentax.c b/libexif/pentax/exif-mnote-data-pentax.c
index 38fbf64..757bb72 100644
--- a/libexif/pentax/exif-mnote-data-pentax.c
+++ b/libexif/pentax/exif-mnote-data-pentax.c
@@ -308,7 +308,7 @@
 				(dataofs + s > buf_size)) {
 				exif_log (en->log, EXIF_LOG_CODE_DEBUG,
 						  "ExifMnoteDataPentax", "Tag data past end "
-					  "of buffer (%zu > %u)", dataofs + s, buf_size);
+					  "of buffer (%u > %u)", dataofs + s, buf_size);
 				continue;
 			}
 
diff --git a/libexif/pentax/mnote-pentax-entry.c b/libexif/pentax/mnote-pentax-entry.c
index dcb1560..7e97c2c 100644
--- a/libexif/pentax/mnote-pentax-entry.c
+++ b/libexif/pentax/mnote-pentax-entry.c
@@ -425,34 +425,24 @@
 		case EXIF_FORMAT_SHORT:
 		  {
 			const unsigned char *data = entry->data;
-		  	size_t k, len = strlen(val), sizeleft;
-
-			sizeleft = entry->size;
+		  	size_t k, len = strlen(val);
 		  	for(k=0; k<entry->components; k++) {
-				if (sizeleft < 2)
-					break;
 				vs = exif_get_short (data, entry->order);
 				snprintf (val+len, maxlen-len, "%i ", vs);
 				len = strlen(val);
 				data += 2;
-				sizeleft -= 2;
 			}
 		  }
 		  break;
 		case EXIF_FORMAT_LONG:
 		  {
 			const unsigned char *data = entry->data;
-		  	size_t k, len = strlen(val), sizeleft;
-
-			sizeleft = entry->size;
+		  	size_t k, len = strlen(val);
 		  	for(k=0; k<entry->components; k++) {
-				if (sizeleft < 4)
-					break;
 				vl = exif_get_long (data, entry->order);
 				snprintf (val+len, maxlen-len, "%li", (long int) vl);
 				len = strlen(val);
 				data += 4;
-				sizeleft -= 4;
 			}
 		  }
 		  break;
@@ -465,5 +455,5 @@
 		break;
 	}
 
-	return val;
+	return (val);
 }
diff --git a/libexif_blocklist.txt b/libexif_blocklist.txt
deleted file mode 100644
index 2c838a7..0000000
--- a/libexif_blocklist.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 2017 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# libexif/canon/exif-mnote-data-canon.c:255:56: 8 * 3435921664 cannot be represented in type 'unsigned long'
-# libexif/canon/exif-mnote-data-canon.c:267:17: 1594425354 + 4028186704 cannot be represented in type 'unsigned int'
-# libexif/canon/exif-mnote-data-canon.c:271:14: 1594425354 + 4028186704 cannot be represented in type 'unsigned int'
-fun:exif_mnote_data_canon_load
-fun:match_tag