Modern Apps git

← Modern-Apps.git

office: fix OdfWriter writing zip before END header is closed

Commit
9b3a8a17a9d6949d41e565119ec1beb6bae64cb9
Author
Vayun Mathur <[email protected]>
When
2026-11-06 18:38 UTC (29 days ago)
Parents
53025d5
buffer.toByteArray() was captured inside ZipOutputStream.use {}, i.e.
before close() writes the END header, truncating every saved file.
Read the bytes after the use block instead.

(cherry picked from commit ec6e71ee9e5d7e630fe076f07619e264cac881ef)

Diff

office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt
diff --git a/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt b/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.ktindex 0f3829ae9f..dc6f1b6f60 100644--- a/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt+++ b/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt@@ -30,12 +30,13 @@ object OdfWriter {         val extraManifest = LinkedHashMap<String, String>(result.manifest)          val buffer = ByteArrayOutputStream()-        val bytes = ZipOutputStream(buffer).use { zipOut ->+        ZipOutputStream(buffer).use { zipOut ->             val save = SaveAcc(contentXml, metaXml, settingsXml, docImages, written, extraManifest)             copySourceEntries(context, sourceUri, document, zipOut, save)             writeMissingEntries(document, zipOut, save, result)-            buffer.toByteArray()         }+        // AFTER the ZipOutputStream is closed (close writes the END header).+        val bytes = buffer.toByteArray()         context.contentResolver.openOutputStream(targetUri)?.use { it.write(bytes) }     }