Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/src/main/java/org/steamlite/ProfileSummary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ private fun LoginCard(model: LiteModel) {
var password by remember { mutableStateOf("") }
val guard by model.steam.guard.collectAsState()
val busy by model.steam.busy.collectAsState()
val closing by model.steam.loginClosing.collectAsState()
LaunchedEffect(guard) { if (guard.isNotEmpty()) password = "" }

val shape = RoundedCornerShape(18.dp)
Expand All @@ -284,13 +285,17 @@ private fun LoginCard(model: LiteModel) {

Spacer(Modifier.height(14.dp))
AccentButton(
if (busy) "登录处理中…" else "登录 Steam",
when {
closing -> "正在断开 Steam 连接…"
busy -> "登录处理中…"
else -> "登录 Steam"
},
{ model.steam.login(username, password) },
Modifier.fillMaxWidth(),
enabled = !busy && username.isNotBlank() && password.isNotEmpty()
)

if (busy) {
if (busy && !closing) {
Spacer(Modifier.height(10.dp))
Text("正在连接 Steam,可能需要几秒", fontSize = 10.5.sp, color = Text3)
Spacer(Modifier.height(8.dp))
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/org/steamlite/SteamApngDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,54 @@ import java.nio.ByteBuffer
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

private const val MAX_APNG_EDGE = 4096
private const val MAX_APNG_PIXELS = 4L * 1024 * 1024
private const val PNG_SIGNATURE = -0x76afb1b8f2f5e5f6L
private const val IHDR = 0x49484452
private const val FCTL = 0x6663544c
private const val IEND = 0x49454e44

internal fun checkApngDimensions(bytes: ByteArray) {
val input = ByteBuffer.wrap(bytes)
check(input.remaining() >= 33 && input.long == PNG_SIGNATURE &&
input.int == 13 && input.int == IHDR) { "Invalid APNG header" }
val width = input.int
val height = input.int
check(width in 1..MAX_APNG_EDGE && height in 1..MAX_APNG_EDGE &&
width.toLong() * height <= MAX_APNG_PIXELS) { "Animated image exceeds dimension limit" }
input.position(33) // Signature, IHDR chunk and CRC.

while (input.remaining() >= 12) {
val length = input.int
val type = input.int
check(length in 0..(input.remaining() - 4) && type != IHDR) { "Invalid APNG chunk" }
val dataStart = input.position()
if (type == FCTL) {
check(length == 26) { "Invalid APNG frame header" }
val frameWidth = input.getInt(dataStart + 4)
val frameHeight = input.getInt(dataStart + 8)
val x = input.getInt(dataStart + 12)
val y = input.getInt(dataStart + 16)
check(frameWidth in 1..width && frameHeight in 1..height &&
x in 0..(width - frameWidth) && y in 0..(height - frameHeight)) { "APNG frame exceeds canvas bounds" }
}
if (type == IEND) {
check(length == 0 && input.remaining() == 4) { "Unexpected data after APNG image" }
return
}
input.position(dataStart + length + 4)
}
error("Incomplete APNG")
}

/** APNG's animation control chunk precedes the first image-data chunk. */
internal class SteamApngDecoder(private val result: SourceResult) : Decoder {
override suspend fun decode(): DecodeResult = withContext(Dispatchers.IO) {
val source = result.source.source()
val buffer = okio.Buffer()
while (source.read(buffer, 8192) != -1L) check(buffer.size <= 20L * 1024 * 1024) { "Animated image exceeds size limit" }
val bytes = buffer.readByteArray()
checkApngDimensions(bytes)
val drawable = APNGDrawable(object : ByteBufferLoader() {
override fun getByteBuffer(): ByteBuffer = ByteBuffer.wrap(bytes)
})
Expand Down
Loading
Loading