Fix crash when sending trimmed videos.

This commit is contained in:
Greyson Parrelli 2024-01-08 11:32:55 -05:00 committed by Alex Hart
parent e0fb102572
commit 80a7db2511

View file

@ -673,7 +673,7 @@ class AttachmentTable(
UPLOAD_TIMESTAMP to uploadTimestamp UPLOAD_TIMESTAMP to uploadTimestamp
) )
if (dataInfo != null && dataInfo.hash != null) { if (dataInfo?.hash != null) {
updateAttachmentAndMatchingHashes(writableDatabase, id, dataInfo.hash, values) updateAttachmentAndMatchingHashes(writableDatabase, id, dataInfo.hash, values)
} else { } else {
writableDatabase writableDatabase
@ -841,7 +841,7 @@ class AttachmentTable(
file = File(cursor.getString(cursor.getColumnIndexOrThrow(dataType))), file = File(cursor.getString(cursor.getColumnIndexOrThrow(dataType))),
length = cursor.requireLong(SIZE), length = cursor.requireLong(SIZE),
random = cursor.requireNonNullBlob(DATA_RANDOM), random = cursor.requireNonNullBlob(DATA_RANDOM),
hash = cursor.requireNonNullString(DATA_HASH), hash = cursor.requireString(DATA_HASH),
transformProperties = TransformProperties.parse(cursor.requireString(TRANSFORM_PROPERTIES)) transformProperties = TransformProperties.parse(cursor.requireString(TRANSFORM_PROPERTIES))
) )
} }
@ -1101,7 +1101,7 @@ class AttachmentTable(
* will be fixed in a later call to [updateAttachmentAndMatchingHashes]. * will be fixed in a later call to [updateAttachmentAndMatchingHashes].
*/ */
private fun isAttachmentFileUsedByOtherAttachments(attachmentId: AttachmentId?, dataInfo: DataInfo): Boolean { private fun isAttachmentFileUsedByOtherAttachments(attachmentId: AttachmentId?, dataInfo: DataInfo): Boolean {
return if (attachmentId == null) { return if (attachmentId == null || dataInfo.hash == null) {
false false
} else { } else {
readableDatabase readableDatabase
@ -1113,7 +1113,7 @@ class AttachmentTable(
private fun updateAttachmentDataHash( private fun updateAttachmentDataHash(
db: SQLiteDatabase, db: SQLiteDatabase,
oldHash: String, oldHash: String?,
newData: DataInfo newData: DataInfo
) { ) {
if (oldHash == null) { if (oldHash == null) {
@ -1287,11 +1287,15 @@ class AttachmentTable(
private fun findDuplicateDataFileInfos( private fun findDuplicateDataFileInfos(
database: SQLiteDatabase, database: SQLiteDatabase,
hash: String, hash: String?,
excludedAttachmentId: AttachmentId? excludedAttachmentId: AttachmentId?
): List<DataInfo> { ): List<DataInfo> {
check(database.inTransaction()) { "Must be in a transaction!" } check(database.inTransaction()) { "Must be in a transaction!" }
if (hash == null) {
return emptyList()
}
val selectorArgs: Pair<String, Array<String>> = buildSharedFileSelectorArgs(hash, excludedAttachmentId) val selectorArgs: Pair<String, Array<String>> = buildSharedFileSelectorArgs(hash, excludedAttachmentId)
return database return database
@ -1428,7 +1432,11 @@ class AttachmentTable(
return attachmentId return attachmentId
} }
private fun findTemplateAttachments(dataHash: String): List<DatabaseAttachment> { private fun findTemplateAttachments(dataHash: String?): List<DatabaseAttachment> {
if (dataHash == null) {
return emptyList()
}
return readableDatabase return readableDatabase
.select(*PROJECTION) .select(*PROJECTION)
.from(TABLE_NAME) .from(TABLE_NAME)
@ -1520,20 +1528,28 @@ class AttachmentTable(
val file: File, val file: File,
val length: Long, val length: Long,
val random: ByteArray, val random: ByteArray,
val hash: String, val hash: String?,
val transformProperties: TransformProperties? val transformProperties: TransformProperties?
) { ) {
override fun equals(o: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === o) return true if (this === other) return true
if (o == null || javaClass != o.javaClass) return false if (javaClass != other?.javaClass) return false
val dataInfo = o as DataInfo
return length == dataInfo.length && file == dataInfo.file && other as DataInfo
Arrays.equals(random, dataInfo.random) && hash == dataInfo.hash && transformProperties == dataInfo.transformProperties
if (file != other.file) return false
if (length != other.length) return false
if (!random.contentEquals(other.random)) return false
if (hash != other.hash) return false
return transformProperties == other.transformProperties
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = Objects.hash(file, length, hash, transformProperties) var result = file.hashCode()
result = 31 * result + Arrays.hashCode(random) result = 31 * result + length.hashCode()
result = 31 * result + random.contentHashCode()
result = 31 * result + (hash?.hashCode() ?: 0)
result = 31 * result + (transformProperties?.hashCode() ?: 0)
return result return result
} }
} }