From 3632e6dc8adb5cb7c3b63cf96a5b8e7217e153a3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Oct 2022 12:32:27 +0200 Subject: [PATCH 1/4] Replace library `org.apache.sanselan:sanselan:0.97-incubator` with `org.apache.commons:commons-imaging:1.0-alpha3` --- dependencies.gradle | 2 +- dependencies_groups.gradle | 1 - .../session/content/ImageExifTagRemover.kt | 35 +++++++++---------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index db4a961648..33a2096a43 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -160,7 +160,7 @@ ext.libs = [ 'emojiGoogle' : "com.vanniktech:emoji-google:$vanniktechEmoji" ], apache : [ - 'commonsImaging' : "org.apache.sanselan:sanselan:0.97-incubator" + 'commonsImaging' : "org.apache.commons:commons-imaging:1.0-alpha3" ], sentry: [ 'sentryAndroid' : "io.sentry:sentry-android:$sentry" diff --git a/dependencies_groups.gradle b/dependencies_groups.gradle index 68de2c1581..8d488ba2f8 100644 --- a/dependencies_groups.gradle +++ b/dependencies_groups.gradle @@ -176,7 +176,6 @@ ext.groups = [ 'org.apache.ant', 'org.apache.commons', 'org.apache.httpcomponents', - 'org.apache.sanselan', 'org.bouncycastle', 'org.ccil.cowan.tagsoup', 'org.checkerframework', diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt index 3fa9ffb0e1..baa441a74d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt @@ -17,11 +17,11 @@ package org.matrix.android.sdk.internal.session.content import kotlinx.coroutines.withContext -import org.apache.sanselan.Sanselan -import org.apache.sanselan.formats.jpeg.JpegImageMetadata -import org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter -import org.apache.sanselan.formats.tiff.constants.ExifTagConstants -import org.apache.sanselan.formats.tiff.constants.GPSTagConstants +import org.apache.commons.imaging.Imaging +import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata +import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter +import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants +import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants import org.matrix.android.sdk.api.MatrixCoroutineDispatchers import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.internal.util.TemporaryFileCreator @@ -46,24 +46,23 @@ internal class ImageExifTagRemover @Inject constructor( */ suspend fun removeSensitiveJpegExifTags(jpegImageFile: File): File = withContext(coroutineDispatchers.io) { val outputSet = tryOrNull("Unable to read JpegImageMetadata") { - (Sanselan.getMetadata(jpegImageFile) as? JpegImageMetadata)?.exif?.outputSet + (Imaging.getMetadata(jpegImageFile) as? JpegImageMetadata)?.exif?.outputSet } ?: return@withContext jpegImageFile tryOrNull("Unable to remove ExifData") { outputSet.removeField(ExifTagConstants.EXIF_TAG_GPSINFO) - outputSet.removeField(ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION_1) - outputSet.removeField(ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION_2) + outputSet.removeField(ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION) outputSet.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_ALTITUDE) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_ALTITUDE_REF) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LONGITUDE) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LONGITUDE_REF) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LONGITUDE) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LONGITUDE_REF) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LATITUDE) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LATITUDE_REF) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LATITUDE) - outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LATITUDE_REF) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LONGITUDE) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LONGITUDE_REF) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LATITUDE) + outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LATITUDE_REF) } ?: return@withContext jpegImageFile val scrubbedFile = temporaryFileCreator.create() From e8046da0ba6ca8891f94c607e82aa12f3fe0a06b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Oct 2022 12:34:03 +0200 Subject: [PATCH 2/4] Use `GpsTagConstants.ALL_GPS_TAGS` to remove all tags related to GPS. --- .../internal/session/content/ImageExifTagRemover.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt index baa441a74d..274a2a85e3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt @@ -53,16 +53,9 @@ internal class ImageExifTagRemover @Inject constructor( outputSet.removeField(ExifTagConstants.EXIF_TAG_GPSINFO) outputSet.removeField(ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION) outputSet.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LONGITUDE) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LONGITUDE_REF) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LATITUDE) - outputSet.removeField(GpsTagConstants.GPS_TAG_GPS_DEST_LATITUDE_REF) + GpsTagConstants.ALL_GPS_TAGS.forEach { tagInfo -> + outputSet.removeField(tagInfo) + } } ?: return@withContext jpegImageFile val scrubbedFile = temporaryFileCreator.create() From c8d08e21a819d24a60ff949b5bda2130441ffe08 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Oct 2022 12:36:58 +0200 Subject: [PATCH 3/4] Small refactor --- .../internal/session/content/ImageExifTagRemover.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt index 274a2a85e3..1531d70083 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt @@ -50,10 +50,7 @@ internal class ImageExifTagRemover @Inject constructor( } ?: return@withContext jpegImageFile tryOrNull("Unable to remove ExifData") { - outputSet.removeField(ExifTagConstants.EXIF_TAG_GPSINFO) - outputSet.removeField(ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION) - outputSet.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT) - GpsTagConstants.ALL_GPS_TAGS.forEach { tagInfo -> + tagsToRemove.forEach { tagInfo -> outputSet.removeField(tagInfo) } } ?: return@withContext jpegImageFile @@ -74,4 +71,12 @@ internal class ImageExifTagRemover @Inject constructor( } ) } + + private val tagsToRemove + get() = GpsTagConstants.ALL_GPS_TAGS + + listOf( + ExifTagConstants.EXIF_TAG_GPSINFO, + ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION, + ExifTagConstants.EXIF_TAG_USER_COMMENT, + ) } From 307b71dbd79f7f15849ed90a19cc52d10ec3b0d5 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Oct 2022 12:40:45 +0200 Subject: [PATCH 4/4] Changelog --- changelog.d/7454.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7454.misc diff --git a/changelog.d/7454.misc b/changelog.d/7454.misc new file mode 100644 index 0000000000..beba9717b8 --- /dev/null +++ b/changelog.d/7454.misc @@ -0,0 +1 @@ +Replace org.apache.sanselan:sanselan by org.apache.commons:commons-imaging