File tree Expand file tree Collapse file tree 2 files changed +6
-7
lines changed
main/java/org/readium/r2/streamer/parser/epub
test/java/org/readium/r2/streamer/parser/epub Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,7 @@ internal class EpubDeobfuscator(
2727 @Suppress(" Unused_parameter" )
2828 fun transform (url : Url , resource : Resource ): Resource =
2929 resource.flatMap {
30- val algorithm = resource.sourceUrl
31- ?.let { encryptionData[it] }
32- ?.algorithm
30+ val algorithm = encryptionData[url]?.algorithm
3331 if (algorithm != null && algorithm2length.containsKey(algorithm)) {
3432 DeobfuscatingResource (resource, algorithm)
3533 } else {
@@ -71,9 +69,10 @@ internal class EpubDeobfuscator(
7169 )
7270
7371 private fun deobfuscate (bytes : ByteArray , obfuscationKey : ByteArray , obfuscationLength : Int ) {
74- val toDeobfuscate = 0 until obfuscationLength
75- for (i in toDeobfuscate)
72+ val toDeobfuscate = 0 until obfuscationLength.coerceAtMost(bytes.size)
73+ for (i in toDeobfuscate) {
7674 bytes[i] = bytes[i].xor(obfuscationKey[i % obfuscationKey.size])
75+ }
7776 }
7877
7978 private fun getHashKeyAdobe (pubId : String ) =
Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ class EpubDeobfuscatorTest {
4545
4646 private fun deobfuscate (url : Url , resource : Resource , algorithm : String? ): Resource {
4747 val encryptionData =
48- if (resource.sourceUrl != null && algorithm != null ) {
49- mapOf (resource.sourceUrl as Url to Encryption (algorithm = algorithm))
48+ if (algorithm != null ) {
49+ mapOf (url to Encryption (algorithm = algorithm))
5050 } else {
5151 emptyMap()
5252 }
You can’t perform that action at this time.
0 commit comments