expo-updates 57.0.25 → 57.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 57.0.27 — 2026-11-05
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - [Android] Fix a startup crash (`Compiling JS failed: Buffer is smaller than the size stated in the file header`) caused by a truncated update asset. Downloaded assets are now moved into place with an atomic rename after the hash is verified, instead of being stream-copied into the final path, and an asset file that already exists on disk is only reused when it matches the hash declared in the manifest. ([#51715](https://github.com/expo/expo/pull/51715) by [@AndreiCalazans](https://github.com/AndreiCalazans))
18
+
19
+ ### 💡 Others
20
+
21
+ - Update `glob` to 14.0.3. ([#52819](https://github.com/expo/expo/pull/52819) by [@kitten](https://github.com/kitten))
22
+
23
+ ## 57.0.26 — 2026-10-12
24
+
25
+ _This version does not introduce any user-facing changes._
26
+
13
27
  ## 57.0.25 — 2026-10-06
14
28
 
15
29
  _This version does not introduce any user-facing changes._
@@ -42,7 +42,7 @@ expoModule {
42
42
  }
43
43
 
44
44
  group = 'host.exp.exponent'
45
- version = '57.0.25'
45
+ version = '57.0.27'
46
46
 
47
47
  // Utility method to derive boolean values from the environment or from Java properties,
48
48
  // and return them as strings to be used in BuildConfig fields
@@ -94,7 +94,7 @@ android {
94
94
  namespace "expo.modules.updates"
95
95
  defaultConfig {
96
96
  versionCode 31
97
- versionName '57.0.25'
97
+ versionName '57.0.27'
98
98
  consumerProguardFiles("proguard-rules.pro")
99
99
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
100
100
 
@@ -113,39 +113,61 @@ object UpdatesUtils {
113
113
  @Throws(NoSuchAlgorithmException::class, IOException::class)
114
114
  fun verifySHA256AndWriteToFile(inputStream: InputStream, destination: File, expectedBase64URLEncodedHash: String?): ByteArray {
115
115
  DigestInputStream(inputStream, MessageDigest.getInstance("SHA-256")).use { digestInputStream ->
116
- // write file atomically by writing it to a temporary path and then renaming
117
- // this protects us against partially written files if the process is interrupted
116
+ // Write to a temporary path first and only move the file into place after the hash is
117
+ // verified. The move is a rename on the same filesystem, so the destination is either absent
118
+ // or complete; it can never be observed partially written. A streamed copy into the
119
+ // destination (the previous implementation) left a truncated file behind when the process
120
+ // was killed mid-copy, and that file was later trusted because it existed.
118
121
  val tmpFile = File(destination.absolutePath + ".tmp")
119
122
  tmpFile.parentFile?.mkdirs()
120
- digestInputStream.use { input ->
121
- tmpFile.outputStream().use { output ->
122
- input.copyTo(output)
123
+ try {
124
+ digestInputStream.use { input ->
125
+ FileOutputStream(tmpFile).use { output ->
126
+ input.copyTo(output)
127
+ // flush to disk before the file becomes visible at the final path, so a reboot or
128
+ // power loss right after the move cannot leave a truncated file behind
129
+ output.fd.sync()
130
+ }
123
131
  }
124
- }
125
132
 
126
- // this message digest must be read after the input stream has been consumed in order to get the hash correctly
127
- val md = digestInputStream.messageDigest
128
- val hash = md.digest()
129
- val hashBase64String = toBase64Url(hash)
130
- if (expectedBase64URLEncodedHash != null && expectedBase64URLEncodedHash != hashBase64String) {
131
- throw IOException("File download was successful but base64url-encoded SHA-256 did not match expected; expected: $expectedBase64URLEncodedHash; actual: $hashBase64String")
132
- }
133
- // only rename after the hash has been verified
134
- // Since renameTo() does not expose detailed errors, and can fail if source and destination
135
- // are not on the same mount point, we do a copyTo followed by delete
136
- // if there are two assets with identical content, they will be written to the same file path,
137
- // so we allow overwrites
138
- try {
139
- tmpFile.copyTo(destination, true)
140
- } catch (e: NoSuchFileException) {
141
- throw IOException("File download was successful, but temp file ${tmpFile.absolutePath} does not exist")
142
- } catch (e: Exception) {
143
- throw IOException("File download was successful, but an exception occurred: $e")
133
+ // this message digest must be read after the input stream has been consumed in order to get the hash correctly
134
+ val md = digestInputStream.messageDigest
135
+ val hash = md.digest()
136
+ val hashBase64String = toBase64Url(hash)
137
+ if (expectedBase64URLEncodedHash != null && expectedBase64URLEncodedHash != hashBase64String) {
138
+ throw IOException("File download was successful but base64url-encoded SHA-256 did not match expected; expected: $expectedBase64URLEncodedHash; actual: $hashBase64String")
139
+ }
140
+
141
+ // if there are two assets with identical content, they will be written to the same file path,
142
+ // so we allow overwrites
143
+ moveFileAtomically(tmpFile, destination)
144
+
145
+ return hash
144
146
  } finally {
145
147
  tmpFile.delete()
146
148
  }
149
+ }
150
+ }
147
151
 
148
- return hash
152
+ /**
153
+ * Moves [source] to [destination], replacing any existing file. The temp file and the destination
154
+ * live in the same directory, so `rename(2)` applies and the move is atomic. If the rename is
155
+ * rejected anyway (for example, the two paths end up on different mount points), fall back to a
156
+ * copy so the download still succeeds.
157
+ */
158
+ @Throws(IOException::class)
159
+ internal fun moveFileAtomically(source: File, destination: File) {
160
+ if (!source.exists()) {
161
+ throw IOException("File download was successful, but temp file ${source.absolutePath} does not exist")
162
+ }
163
+ if (source.renameTo(destination)) {
164
+ return
165
+ }
166
+ Log.w(TAG, "Atomic rename of ${source.absolutePath} to ${destination.absolutePath} failed; falling back to copy")
167
+ try {
168
+ source.copyTo(destination, true)
169
+ } catch (e: Exception) {
170
+ throw IOException("File download was successful, but an exception occurred: $e")
149
171
  }
150
172
  }
151
173
 
@@ -747,47 +747,85 @@ class FileDownloader(
747
747
  val path = File(destinationDirectory, filename)
748
748
 
749
749
  if (path.exists()) {
750
- asset.relativePath = filename
751
- return AssetDownloadResult(asset, false)
752
- } else {
753
- val canApplyPatch =
754
- asset.isLaunchAsset &&
755
- launchedUpdate != null &&
756
- requestedUpdate != null &&
757
- launchedUpdate.id != requestedUpdate.id
750
+ if (isExistingAssetFileValid(path, asset, requestedUpdate)) {
751
+ asset.relativePath = filename
752
+ return AssetDownloadResult(asset, false)
753
+ }
754
+ // the file on disk is not the asset we expect (for example, it was truncated when a previous
755
+ // process was killed); throw it away and download again
756
+ path.delete()
757
+ }
758
758
 
759
- try {
760
- val downloadResult = downloadAssetAndVerifyHashAndWriteToPath(
759
+ val canApplyPatch =
760
+ asset.isLaunchAsset &&
761
+ launchedUpdate != null &&
762
+ requestedUpdate != null &&
763
+ launchedUpdate.id != requestedUpdate.id
764
+
765
+ try {
766
+ val downloadResult = downloadAssetAndVerifyHashAndWriteToPath(
767
+ asset,
768
+ extraHeaders,
769
+ createRequestForAsset(
761
770
  asset,
762
771
  extraHeaders,
763
- createRequestForAsset(
764
- asset,
765
- extraHeaders,
766
- configuration,
767
- allowPatch = canApplyPatch
768
- ),
769
- asset.expectedHash,
770
- path,
771
- destinationDirectory,
772
- assetLoadProgressListener?.let { listener -> { listener.invoke(it) } },
773
- allowPatch = canApplyPatch,
774
- launchedUpdate = launchedUpdate,
775
- requestedUpdate = requestedUpdate,
776
- embeddedAssetExtractor = embeddedAssetExtractor
777
- )
772
+ configuration,
773
+ allowPatch = canApplyPatch
774
+ ),
775
+ asset.expectedHash,
776
+ path,
777
+ destinationDirectory,
778
+ assetLoadProgressListener?.let { listener -> { listener.invoke(it) } },
779
+ allowPatch = canApplyPatch,
780
+ launchedUpdate = launchedUpdate,
781
+ requestedUpdate = requestedUpdate,
782
+ embeddedAssetExtractor = embeddedAssetExtractor
783
+ )
778
784
 
779
- asset.downloadTime = Date()
780
- asset.relativePath = filename
781
- asset.hash = downloadResult.hash
782
- return AssetDownloadResult(asset, true)
783
- } catch (e: Exception) {
784
- val message = "Failed to download asset ${asset.key}"
785
- logger.error(message, e, UpdatesErrorCode.AssetsFailedToLoad)
786
- throw IOException(message, e)
787
- }
785
+ asset.downloadTime = Date()
786
+ asset.relativePath = filename
787
+ asset.hash = downloadResult.hash
788
+ return AssetDownloadResult(asset, true)
789
+ } catch (e: Exception) {
790
+ val message = "Failed to download asset ${asset.key}"
791
+ logger.error(message, e, UpdatesErrorCode.AssetsFailedToLoad)
792
+ throw IOException(message, e)
788
793
  }
789
794
  }
790
795
 
796
+ /**
797
+ * An asset file that already exists on disk is only reused when its contents match the hash the
798
+ * manifest declares for the asset. Trusting the file because it exists is unsafe: a process
799
+ * killed while the file was being written leaves a truncated file behind, and the launch asset
800
+ * then fails to load with a Hermes `Buffer is smaller than the size stated in the file header`
801
+ * error. When the manifest has no hash for the asset there is nothing to verify against, so the
802
+ * file is reused as before.
803
+ */
804
+ private fun isExistingAssetFileValid(path: File, asset: AssetEntity, requestedUpdate: UpdateEntity?): Boolean {
805
+ val expectedHash = asset.expectedHash ?: return true
806
+ val actualHash = try {
807
+ UpdatesUtils.toBase64Url(UpdatesUtils.sha256(path))
808
+ } catch (e: Exception) {
809
+ logger.warn(
810
+ "Failed to hash existing file for asset ${asset.key}; re-downloading: ${e.message}",
811
+ UpdatesErrorCode.AssetsFailedToLoad,
812
+ requestedUpdate?.id?.toString(),
813
+ asset.key
814
+ )
815
+ return false
816
+ }
817
+ if (actualHash == expectedHash) {
818
+ return true
819
+ }
820
+ logger.warn(
821
+ "Existing file for asset ${asset.key} did not match expected hash (size ${path.length()} bytes); re-downloading",
822
+ UpdatesErrorCode.AssetsFailedToLoad,
823
+ requestedUpdate?.id?.toString(),
824
+ asset.key
825
+ )
826
+ return false
827
+ }
828
+
791
829
  private suspend fun downloadData(request: Request, progressListener: FileDownloadProgressListener? = null): Response =
792
830
  suspendCancellableCoroutine { continuation ->
793
831
  val call = client.newCall(request)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-updates",
3
- "version": "57.0.25",
3
+ "version": "57.0.27",
4
4
  "description": "Fetches and manages remotely-hosted assets and updates to your app's JS bundle.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@expo/code-signing-certificates": "^0.0.6",
32
- "@expo/plist": "^0.8.1",
32
+ "@expo/plist": "^0.8.2",
33
33
  "@expo/spawn-async": "^1.8.0",
34
34
  "arg": "^4.1.0",
35
35
  "chalk": "^4.1.2",
@@ -39,7 +39,7 @@
39
39
  "expo-structured-headers": "~57.0.1",
40
40
  "expo-updates-interface": "~57.0.2",
41
41
  "getenv": "^2.0.0",
42
- "glob": "^13.0.0",
42
+ "glob": "^14.0.3",
43
43
  "ignore": "^5.3.1",
44
44
  "nullthrows": "^1.1.1",
45
45
  "resolve-from": "^5.0.0"
@@ -60,10 +60,10 @@
60
60
  "picomatch": "^4.0.4",
61
61
  "ts-node": "^10.9.2",
62
62
  "xstate": "^4.37.2",
63
- "expo": "57.0.27",
64
- "expo-dev-client": "57.0.19",
65
- "@expo/metro-config": "57.0.13",
66
- "expo-module-scripts": "56.0.3"
63
+ "expo-module-scripts": "56.0.3",
64
+ "expo-dev-client": "57.0.21",
65
+ "expo": "57.0.32",
66
+ "@expo/metro-config": "57.0.14"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "expo": "*",
@@ -82,7 +82,7 @@
82
82
  "./scripts/with-node.sh"
83
83
  ]
84
84
  },
85
- "gitHead": "50ac74f1ab5682c8e32b24da6e5e97dd4dbbb80f",
85
+ "gitHead": "d525588681ae2ac2863deff25d35daa39ede8ac1",
86
86
  "scripts": {
87
87
  "build": "expo-module build",
88
88
  "clean": "expo-module clean",