Skip to content

Commit c78a1c5

Browse files
Eino-Ville Talvalaandi34
authored andcommitted
Camera metadata: Check for inconsistent data count
Also check for overflow of data/entry count on append. Bug: 30591838 Change-Id: Ibf4c3c6e236cdb28234f3125055d95ef0a2416a2 (cherry picked from commit 241ff3e)
1 parent f33d55e commit c78a1c5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

camera/src/camera_metadata.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
#define _GNU_SOURCE // for fdprintf
17+
#include <inttypes.h>
1718
#include <system/camera_metadata.h>
1819

1920
#define LOG_TAG "camera_metadata"
@@ -380,6 +381,14 @@ int validate_camera_metadata_structure(const camera_metadata_t *metadata,
380381
return ERROR;
381382
}
382383

384+
if (metadata->data_count > metadata->data_capacity) {
385+
ALOGE("%s: Data count (%" PRIu32 ") should be <= data capacity "
386+
"(%" PRIu32 ")",
387+
__FUNCTION__, metadata->data_count, metadata->data_capacity);
388+
android_errorWriteLog(SN_EVENT_LOG_ID, "30591838");
389+
return ERROR;
390+
}
391+
383392
uptrdiff_t entries_end = metadata->entries_start + metadata->entry_capacity;
384393
if (entries_end < metadata->entries_start || // overflow check
385394
entries_end > metadata->data_start) {
@@ -482,6 +491,10 @@ int append_camera_metadata(camera_metadata_t *dst,
482491
const camera_metadata_t *src) {
483492
if (dst == NULL || src == NULL ) return ERROR;
484493

494+
// Check for overflow
495+
if (src->entry_count + dst->entry_count < src->entry_count) return ERROR;
496+
if (src->data_count + dst->data_count < src->data_count) return ERROR;
497+
// Check for space
485498
if (dst->entry_capacity < src->entry_count + dst->entry_count) return ERROR;
486499
if (dst->data_capacity < src->data_count + dst->data_count) return ERROR;
487500

0 commit comments

Comments
 (0)