Skip to content

Commit

Permalink
Disable binary XML format yield
Browse files Browse the repository at this point in the history
Differential Revision: D64572865
  • Loading branch information
Abbondanzo authored and facebook-github-bot committed Oct 18, 2024
1 parent 34c6456 commit 648e688
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ImageFormatChecker private constructor() {
private var maxHeaderLength = 0
private var customImageFormatCheckers: List<FormatChecker>? = null
private val defaultFormatChecker = DefaultImageFormatChecker()
private var binaryXmlEnabled = false

init {
updateMaxHeaderLength()
Expand All @@ -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
}
Expand Down

0 comments on commit 648e688

Please sign in to comment.