fix: treat a product.db with a damaged install record as unreadable

This commit is contained in:
maxjivi05 authored and MaxsTechReview committed 2026-10-26 10:30:16 -04:00
1 parent 538b5c5270
commit e492a78f55
2 files changed
+4 -3

No files matched your search

@@ -252,7 +252,7 @@ object BattleNet {
internal fun productDbEntries(bytes: ByteArray): List<Pair<String, String>>? {
val installs = runCatching { fields(bytes, 0, bytes.size) }.getOrNull()?.filter { it.first == 1 }?.takeIf { it.isNotEmpty() } ?: return null
return installs.mapNotNull { (_, start, end) ->
return installs.map { (_, start, end) ->
runCatching {
val install = fields(bytes, start, end)
val uid = install.firstOrNull { it.first == 1 }?.let { String(bytes, it.second, it.third - it.second) }
@@ -261,8 +261,8 @@ object BattleNet {
val installed = install.firstOrNull { it.first == 4 }?.let { s -> fields(bytes, s.second, s.third).firstOrNull { it.first == 1 } }
?.let { s -> varints(bytes, s.second, s.third)[1] }
if (uid.isNullOrEmpty() || path.isNullOrEmpty() || installed == 0L) null else uid to path
}.getOrNull()
}
}.getOrElse { return null }
}.filterNotNull()
}
private fun fields(bytes: ByteArray, from: Int, to: Int): List<Triple<Int, Int, Int>> = walk(bytes, from, to) { _, _ -> }
@@ -215,6 +215,7 @@ class BattleNetTest {
assertNull(BattleNet.productDbEntries(db.copyOf(db.size - 3)))
assertNull(BattleNet.productDbEntries(byteArrayOf(0x0a, 0x7f, 0x01)))
assertNull(BattleNet.productDbEntries(ByteArray(0)))
assertNull(BattleNet.productDbEntries(byteArrayOf(0x0a, 0x03, 0x0a, 0x7f, 0x01)))
assertEquals(emptyList<Pair<String, String>>(), BattleNet.productDbEntries(message(field(1, message(field(1, "s1"), field(3, message(field(1, "Z:/Games/StarCraft"))), field(4, message(field(1, message(varintField(1, 0))))))))))
}