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 dfc5ff2
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,37 @@ class ImageFormatChecker private constructor() {
private var maxHeaderLength = 0
private var customImageFormatCheckers: List<FormatChecker>? = null
private val defaultFormatChecker = DefaultImageFormatChecker()
private var binaryXmlEnabled = false

init {
updateMaxHeaderLength()
}

fun setCustomImageFormatCheckers(customImageFormatCheckers: List<FormatChecker>?) {
fun setCustomImageFormatCheckers(
customImageFormatCheckers: List<FormatChecker>?
): ImageFormatChecker {
this.customImageFormatCheckers = customImageFormatCheckers
updateMaxHeaderLength()
return this
}

fun setBinaryXmlEnabled(binaryXmlEnabled: Boolean): ImageFormatChecker {
this.binaryXmlEnabled = binaryXmlEnabled
return this
}

@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 dfc5ff2

Please sign in to comment.