From 648e688b83feb4cdddcf9817dfa3b5c7c96a6594 Mon Sep 17 00:00:00 2001 From: Peter Abbondanzo Date: Thu, 17 Oct 2024 17:03:08 -0700 Subject: [PATCH] Disable binary XML format yield Differential Revision: D64572865 --- .../com/facebook/imageformat/ImageFormatChecker.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/imagepipeline-base/src/main/java/com/facebook/imageformat/ImageFormatChecker.kt b/imagepipeline-base/src/main/java/com/facebook/imageformat/ImageFormatChecker.kt index e30f670711..c9058611c6 100644 --- a/imagepipeline-base/src/main/java/com/facebook/imageformat/ImageFormatChecker.kt +++ b/imagepipeline-base/src/main/java/com/facebook/imageformat/ImageFormatChecker.kt @@ -21,6 +21,7 @@ class ImageFormatChecker private constructor() { private var maxHeaderLength = 0 private var customImageFormatCheckers: List? = null private val defaultFormatChecker = DefaultImageFormatChecker() + private var binaryXmlEnabled = false init { updateMaxHeaderLength() @@ -31,11 +32,22 @@ class ImageFormatChecker private constructor() { updateMaxHeaderLength() } + fun setBinaryXmlEnabled(binaryXmlEnabled: Boolean) { + this.binaryXmlEnabled = binaryXmlEnabled + } + @Throws(IOException::class) fun determineImageFormat(`is`: InputStream): ImageFormat { val imageHeaderBytes = ByteArray(maxHeaderLength) val headerSize = readHeaderFromStream(maxHeaderLength, `is`, imageHeaderBytes) val format = defaultFormatChecker.determineFormat(imageHeaderBytes, headerSize) + if (format == DefaultImageFormats.BINARY_XML) { + return if (binaryXmlEnabled) { + format + } else { + ImageFormat.UNKNOWN + } + } if (format !== ImageFormat.UNKNOWN) { return format }