This commit is contained in:
Evan You
2025-05-07 20:23:34 +08:00
parent bd87d281f5
commit 8e55f4cfb6
4 changed files with 15 additions and 12 deletions

View File

@@ -16,8 +16,8 @@ android {
applicationId = "com.donut.mixfile"
minSdk = 26
targetSdk = 35
versionCode = 127
versionName = "1.16.9"
versionCode = 128
versionName = "1.16.10"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@@ -56,7 +56,8 @@ suspend fun decryptAES(
var size = 0
withContext(Dispatchers.IO) {
while (!data.isClosedForRead) {
if (size >= limit) {
// +12字节ghash 大小,iv已读取
if (size >= limit + 12) {
throw Exception("分片文件过大")
}
val buffer = data.readRemaining(1024 * 64).readByteArray()

View File

@@ -106,12 +106,13 @@ data class MixShareInfo(
}
}.execute {
val contentLength = it.contentLength() ?: 0
if (contentLength > (limit + headSize + 192)) {
// iv + ghash 各96位,12字节,共24字节
if (contentLength > (limit + headSize + 24)) {
throw Exception("分片文件过大")
}
val channel = it.bodyAsChannel()
channel.discard(headSize.toLong())
decryptAES(channel, ENCODER.decode(key), limit + 96)
decryptAES(channel, ENCODER.decode(key), limit)
}
val hash = Url(url).fragment.trim()
if (hash.isNotEmpty()) {
@@ -136,8 +137,8 @@ data class MixShareInfo(
fun contentType() = fileName.parseFileMimeType()
suspend fun fetchMixFile(client: HttpClient): MixFile {
val decryptedBytes = fetchFile(url, client = client)
suspend fun fetchMixFile(client: HttpClient, referer: String = this.referer): MixFile {
val decryptedBytes = fetchFile(url, client = client, referer = referer)
return MixFile.fromBytes(decryptedBytes)
}

View File

@@ -47,8 +47,13 @@ fun MixFileServer.getDownloadRoute(): RoutingHandler {
suspend fun MixFileServer.respondMixFile(call: ApplicationCall, shareInfo: MixShareInfo) {
val param = call.parameters
val referer = param["referer"].ifNullOrBlank { shareInfo.referer }
val name = param["name"].ifNullOrBlank { shareInfo.fileName }
val mixFile = try {
shareInfo.fetchMixFile(httpClient)
shareInfo.fetchMixFile(httpClient, referer)
} catch (e: Exception) {
call.respondText(
"解析文件索引失败: ${e.stackTraceToString()}",
@@ -57,10 +62,6 @@ suspend fun MixFileServer.respondMixFile(call: ApplicationCall, shareInfo: MixSh
return
}
val referer = param["referer"].ifNullOrBlank { shareInfo.referer }
val name = param["name"].ifNullOrBlank { shareInfo.fileName }
var contentLength = shareInfo.fileSize
val range: LongRange? = call.request.ranges()?.mergeToSingle(contentLength)
call.response.apply {