Skip to content

Commit e41b1a6

Browse files
authored
Merge pull request #7454 from vector-im/feature/bma/upgrade_sanselan
Replace org.apache.sanselan:sanselan by org.apache.commons:commons-imaging
2 parents e8bf799 + 307b71d commit e41b1a6

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

changelog.d/7454.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace org.apache.sanselan:sanselan by org.apache.commons:commons-imaging

dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ ext.libs = [
160160
'emojiGoogle' : "com.vanniktech:emoji-google:$vanniktechEmoji"
161161
],
162162
apache : [
163-
'commonsImaging' : "org.apache.sanselan:sanselan:0.97-incubator"
163+
'commonsImaging' : "org.apache.commons:commons-imaging:1.0-alpha3"
164164
],
165165
sentry: [
166166
'sentryAndroid' : "io.sentry:sentry-android:$sentry"

dependencies_groups.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ ext.groups = [
176176
'org.apache.ant',
177177
'org.apache.commons',
178178
'org.apache.httpcomponents',
179-
'org.apache.sanselan',
180179
'org.bouncycastle',
181180
'org.ccil.cowan.tagsoup',
182181
'org.checkerframework',

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/ImageExifTagRemover.kt

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package org.matrix.android.sdk.internal.session.content
1818

1919
import kotlinx.coroutines.withContext
20-
import org.apache.sanselan.Sanselan
21-
import org.apache.sanselan.formats.jpeg.JpegImageMetadata
22-
import org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter
23-
import org.apache.sanselan.formats.tiff.constants.ExifTagConstants
24-
import org.apache.sanselan.formats.tiff.constants.GPSTagConstants
20+
import org.apache.commons.imaging.Imaging
21+
import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata
22+
import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter
23+
import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants
24+
import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants
2525
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
2626
import org.matrix.android.sdk.api.extensions.tryOrNull
2727
import org.matrix.android.sdk.internal.util.TemporaryFileCreator
@@ -46,24 +46,13 @@ internal class ImageExifTagRemover @Inject constructor(
4646
*/
4747
suspend fun removeSensitiveJpegExifTags(jpegImageFile: File): File = withContext(coroutineDispatchers.io) {
4848
val outputSet = tryOrNull("Unable to read JpegImageMetadata") {
49-
(Sanselan.getMetadata(jpegImageFile) as? JpegImageMetadata)?.exif?.outputSet
49+
(Imaging.getMetadata(jpegImageFile) as? JpegImageMetadata)?.exif?.outputSet
5050
} ?: return@withContext jpegImageFile
5151

5252
tryOrNull("Unable to remove ExifData") {
53-
outputSet.removeField(ExifTagConstants.EXIF_TAG_GPSINFO)
54-
outputSet.removeField(ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION_1)
55-
outputSet.removeField(ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION_2)
56-
outputSet.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT)
57-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_ALTITUDE)
58-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_ALTITUDE_REF)
59-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LONGITUDE)
60-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LONGITUDE_REF)
61-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LONGITUDE)
62-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LONGITUDE_REF)
63-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LATITUDE)
64-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_LATITUDE_REF)
65-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LATITUDE)
66-
outputSet.removeField(GPSTagConstants.GPS_TAG_GPS_DEST_LATITUDE_REF)
53+
tagsToRemove.forEach { tagInfo ->
54+
outputSet.removeField(tagInfo)
55+
}
6756
} ?: return@withContext jpegImageFile
6857

6958
val scrubbedFile = temporaryFileCreator.create()
@@ -82,4 +71,12 @@ internal class ImageExifTagRemover @Inject constructor(
8271
}
8372
)
8473
}
74+
75+
private val tagsToRemove
76+
get() = GpsTagConstants.ALL_GPS_TAGS +
77+
listOf(
78+
ExifTagConstants.EXIF_TAG_GPSINFO,
79+
ExifTagConstants.EXIF_TAG_SUBJECT_LOCATION,
80+
ExifTagConstants.EXIF_TAG_USER_COMMENT,
81+
)
8582
}

0 commit comments

Comments
 (0)