kobako 0.29.0 → 0.31.0

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.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +552 -10
  4. data/Cargo.lock +595 -139
  5. data/README.md +126 -564
  6. data/ROADMAP.md +3 -2
  7. data/crates/kobako-runtime/CHANGELOG.md +488 -1
  8. data/crates/kobako-runtime/Cargo.toml +73 -15
  9. data/crates/kobako-runtime/README.md +11 -4
  10. data/crates/kobako-runtime/src/cred.rs +124 -0
  11. data/crates/kobako-runtime/src/dispatch.rs +5 -6
  12. data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
  13. data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
  14. data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
  15. data/crates/kobako-runtime/src/endpoint.rs +267 -0
  16. data/crates/kobako-runtime/src/errno.rs +391 -0
  17. data/crates/kobako-runtime/src/error.rs +31 -10
  18. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  19. data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
  20. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
  21. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
  22. data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
  23. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
  24. data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
  25. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
  26. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
  29. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
  30. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
  31. data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
  32. data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
  33. data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
  34. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  35. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
  36. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
  37. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
  38. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
  39. data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
  40. data/crates/kobako-runtime/src/filesystem.rs +25 -388
  41. data/crates/kobako-runtime/src/fork.rs +96 -0
  42. data/crates/kobako-runtime/src/grant.rs +3 -0
  43. data/crates/kobako-runtime/src/hashtable.rs +46 -0
  44. data/crates/kobako-runtime/src/lib.rs +27 -11
  45. data/crates/kobako-runtime/src/limits.rs +195 -0
  46. data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
  47. data/crates/kobako-runtime/src/locking.rs +228 -0
  48. data/crates/kobako-runtime/src/memcg.rs +383 -0
  49. data/crates/kobako-runtime/src/mount.rs +86 -101
  50. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  51. data/crates/kobako-runtime/src/net/connections.rs +179 -0
  52. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  53. data/crates/kobako-runtime/src/net/egress.rs +160 -0
  54. data/crates/kobako-runtime/src/net/family.rs +181 -0
  55. data/crates/kobako-runtime/src/net/http.rs +2733 -0
  56. data/crates/kobako-runtime/src/net/lookup.rs +285 -0
  57. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  58. data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
  59. data/crates/kobako-runtime/src/net/reactor.rs +531 -0
  60. data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
  61. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
  62. data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
  63. data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
  64. data/crates/kobako-runtime/src/net/resolv.rs +227 -0
  65. data/crates/kobako-runtime/src/net/socket.rs +870 -0
  66. data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
  67. data/crates/kobako-runtime/src/net/tls.rs +58 -0
  68. data/crates/kobako-runtime/src/net/transport.rs +279 -0
  69. data/crates/kobako-runtime/src/net/udp.rs +1003 -0
  70. data/crates/kobako-runtime/src/net.rs +42 -0
  71. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  72. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  73. data/crates/kobako-runtime/src/network.rs +551 -0
  74. data/crates/kobako-runtime/src/policy.rs +16 -0
  75. data/crates/kobako-runtime/src/profile.rs +37 -16
  76. data/crates/kobako-runtime/src/runtime.rs +3 -5
  77. data/crates/kobako-runtime/src/sched.rs +311 -0
  78. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  79. data/crates/kobako-runtime/src/security/hooks.rs +242 -0
  80. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  81. data/crates/kobako-runtime/src/security.rs +601 -0
  82. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  83. data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
  84. data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
  85. data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
  86. data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
  87. data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
  88. data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
  89. data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
  90. data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
  91. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  92. data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
  93. data/crates/kobako-runtime/src/vfs/path.rs +64 -0
  94. data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
  95. data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
  96. data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
  97. data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
  98. data/crates/kobako-runtime/src/vfs.rs +63 -0
  99. data/crates/kobako-runtime/src/wait.rs +356 -0
  100. data/crates/kobako-transport/CHANGELOG.md +39 -2
  101. data/crates/kobako-transport/Cargo.toml +3 -3
  102. data/crates/kobako-transport/README.md +8 -8
  103. data/crates/kobako-transport/src/abi.rs +78 -72
  104. data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
  105. data/crates/kobako-transport/src/envelope/call.rs +37 -9
  106. data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
  107. data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
  108. data/crates/kobako-transport/src/envelope/fault.rs +2 -2
  109. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  110. data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
  111. data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
  112. data/crates/kobako-transport/src/envelope/reply.rs +29 -29
  113. data/crates/kobako-transport/src/envelope/request.rs +2 -2
  114. data/crates/kobako-transport/src/envelope/run.rs +1 -1
  115. data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
  116. data/crates/kobako-transport/src/envelope.rs +15 -10
  117. data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
  118. data/crates/kobako-wasmtime/Cargo.toml +35 -15
  119. data/crates/kobako-wasmtime/README.md +11 -6
  120. data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
  121. data/crates/kobako-wasmtime/build.rs +16 -0
  122. data/crates/kobako-wasmtime/src/abi.rs +19 -47
  123. data/crates/kobako-wasmtime/src/ambient.rs +33 -19
  124. data/crates/kobako-wasmtime/src/cache.rs +28 -20
  125. data/crates/kobako-wasmtime/src/config.rs +59 -60
  126. data/crates/kobako-wasmtime/src/driver.rs +63 -145
  127. data/crates/kobako-wasmtime/src/exports.rs +147 -32
  128. data/crates/kobako-wasmtime/src/guest.rs +44 -0
  129. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  130. data/crates/kobako-wasmtime/src/imports.rs +48 -18
  131. data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
  132. data/crates/kobako-wasmtime/src/invocation.rs +93 -51
  133. data/crates/kobako-wasmtime/src/lib.rs +6 -7
  134. data/crates/kobako-wasmtime/src/limiter.rs +52 -211
  135. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
  136. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
  137. data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
  138. data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
  139. data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
  140. data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
  141. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
  142. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
  143. data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
  144. data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
  145. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
  146. data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
  147. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
  148. data/crates/kobako-wasmtime/src/preview1.rs +471 -416
  149. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  150. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  151. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  152. data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
  153. data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
  154. data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
  155. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  156. data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
  157. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  158. data/crates/kobako-wasmtime/src/trap.rs +31 -16
  159. data/crates/kobako-wasmtime/src/wasi.rs +238 -93
  160. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  161. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  162. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  163. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  164. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  165. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  166. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  167. data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
  168. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
  169. data/data/kobako.wasm +0 -0
  170. data/ext/kobako/Cargo.toml +1 -1
  171. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
  172. data/ext/kobako/src/escape.rs +98 -0
  173. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
  174. data/ext/kobako/src/filesystem/ruby.rs +689 -0
  175. data/ext/kobako/src/filesystem.rs +217 -0
  176. data/ext/kobako/src/gvl.rs +306 -0
  177. data/ext/kobako/src/lib.rs +64 -3
  178. data/ext/kobako/src/network/mock.rs +187 -0
  179. data/ext/kobako/src/network.rs +591 -0
  180. data/ext/kobako/src/runtime/bridge.rs +31 -30
  181. data/ext/kobako/src/runtime/snapshot.rs +5 -5
  182. data/ext/kobako/src/runtime.rs +221 -138
  183. data/ext/kobako/src/wire.rs +42 -0
  184. data/lib/kobako/catalog/extensions.rb +19 -7
  185. data/lib/kobako/catalog/flags.rb +4 -6
  186. data/lib/kobako/catalog/grants.rb +5 -4
  187. data/lib/kobako/catalog/handles.rb +9 -31
  188. data/lib/kobako/catalog/mount.rb +12 -12
  189. data/lib/kobako/catalog/network.rb +35 -0
  190. data/lib/kobako/catalog/replacements.rb +28 -0
  191. data/lib/kobako/catalog/services.rb +7 -21
  192. data/lib/kobako/catalog/snippets.rb +10 -25
  193. data/lib/kobako/catalog.rb +4 -1
  194. data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
  195. data/lib/kobako/codec/decoder.rb +12 -12
  196. data/lib/kobako/codec/ext_types.rb +5 -7
  197. data/lib/kobako/codec/handle_walk.rb +5 -47
  198. data/lib/kobako/codec/nesting.rb +7 -7
  199. data/lib/kobako/codec/value_budget.rb +134 -42
  200. data/lib/kobako/codec.rb +1 -1
  201. data/lib/kobako/context.rb +28 -15
  202. data/lib/kobako/errors.rb +15 -12
  203. data/lib/kobako/extension.rb +3 -2
  204. data/lib/kobako/filesystem.rb +53 -15
  205. data/lib/kobako/handle.rb +2 -2
  206. data/lib/kobako/names.rb +28 -0
  207. data/lib/kobako/network.rb +210 -0
  208. data/lib/kobako/outcome.rb +7 -7
  209. data/lib/kobako/payload/arguments.rb +2 -2
  210. data/lib/kobako/pool.rb +47 -25
  211. data/lib/kobako/runtime.rb +3 -2
  212. data/lib/kobako/sandbox.rb +113 -56
  213. data/lib/kobako/sandbox_options.rb +41 -107
  214. data/lib/kobako/snippet/bytecode.rb +1 -1
  215. data/lib/kobako/snippet/source.rb +1 -1
  216. data/lib/kobako/transport/argument_wrap.rb +64 -0
  217. data/lib/kobako/transport/block_failure.rb +1 -1
  218. data/lib/kobako/transport/dispatcher.rb +10 -10
  219. data/lib/kobako/transport/exposure.rb +28 -17
  220. data/lib/kobako/transport/reflection.rb +28 -11
  221. data/lib/kobako/transport/run.rb +13 -28
  222. data/lib/kobako/transport/yielder.rb +3 -10
  223. data/lib/kobako/transport.rb +1 -0
  224. data/lib/kobako/version.rb +1 -1
  225. data/lib/kobako.rb +38 -0
  226. data/release-please-config.json +16 -0
  227. data/sig/core/thread.rbs +6 -0
  228. data/sig/kobako/catalog/extensions.rbs +5 -3
  229. data/sig/kobako/catalog/grants.rbs +7 -4
  230. data/sig/kobako/catalog/handles.rbs +2 -4
  231. data/sig/kobako/catalog/mount.rbs +3 -5
  232. data/sig/kobako/catalog/network.rbs +20 -0
  233. data/sig/kobako/catalog/replacements.rbs +14 -0
  234. data/sig/kobako/catalog/services.rbs +1 -5
  235. data/sig/kobako/catalog/snippets.rbs +3 -5
  236. data/sig/kobako/catalog.rbs +1 -1
  237. data/sig/kobako/codec/boundary.rbs +9 -0
  238. data/sig/kobako/codec/decoder.rbs +1 -1
  239. data/sig/kobako/codec/handle_walk.rbs +0 -6
  240. data/sig/kobako/codec/nesting.rbs +2 -2
  241. data/sig/kobako/codec/value_budget.rbs +48 -5
  242. data/sig/kobako/codec.rbs +1 -2
  243. data/sig/kobako/context.rbs +4 -2
  244. data/sig/kobako/errors.rbs +4 -4
  245. data/sig/kobako/filesystem.rbs +38 -15
  246. data/sig/kobako/guest_yielder.rbs +1 -1
  247. data/sig/kobako/network.rbs +115 -0
  248. data/sig/kobako/outcome.rbs +1 -1
  249. data/sig/kobako/payload/arguments.rbs +1 -1
  250. data/sig/kobako/pool.rbs +8 -4
  251. data/sig/kobako/runtime.rbs +32 -3
  252. data/sig/kobako/sandbox.rbs +22 -7
  253. data/sig/kobako/sandbox_options.rbs +29 -38
  254. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  255. data/sig/kobako/transport/dispatcher.rbs +2 -2
  256. data/sig/kobako/transport/error.rbs +1 -1
  257. data/sig/kobako/transport/exposure.rbs +3 -5
  258. data/sig/kobako/transport/reflection.rbs +12 -2
  259. data/sig/kobako/transport/run.rbs +3 -5
  260. data/sig/kobako/transport/yielder.rbs +0 -3
  261. data/sig/kobako/transport.rbs +2 -2
  262. data/sig/kobako.rbs +13 -0
  263. metadata +131 -34
  264. data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
  265. data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
  266. data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
  267. data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
  268. data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
  269. data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
  270. data/crates/kobako-wasmtime/src/capture.rs +0 -96
  271. data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
  272. data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
  273. data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
  274. data/crates/kobako-wasmtime/src/io.rs +0 -89
  275. data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
  276. data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
  277. data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
  278. data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
  279. data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
  280. data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
  281. data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
  282. data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
  283. data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
  284. data/ext/kobako/src/runtime/escape.rs +0 -53
  285. data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
  286. data/ext/kobako/src/runtime/filesystem.rs +0 -236
  287. data/ext/kobako/src/runtime/gvl.rs +0 -112
  288. data/lib/kobako/constant_name.rb +0 -8
  289. data/sig/kobako/codec/utils.rbs +0 -9
  290. data/sig/kobako/constant_name.rbs +0 -3
  291. /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
@@ -1,4 +1,4 @@
1
- //! Byte primitives for the core envelope: unsigned big-endian integers,
1
+ //! Byte primitives for the Envelope: unsigned big-endian integers,
2
2
  //! length-prefixed byte strings, counted lists, and the trailing remainder.
3
3
  //!
4
4
  //! `Reader` borrows rather than copies, so a decoded envelope's payload is
@@ -7,7 +7,7 @@
7
7
 
8
8
  use super::DecodeError;
9
9
 
10
- const MALFORMED: DecodeError = DecodeError::new("core envelope ended before its declared length");
10
+ const MALFORMED: DecodeError = DecodeError::new("Envelope ended before its declared length");
11
11
 
12
12
  /// Cursor over one message. Every read either advances past a complete
13
13
  /// field or fails, so a truncated message can never be mistaken for a
@@ -22,13 +22,13 @@ impl<'a> Reader<'a> {
22
22
  Reader { bytes, pos: 0 }
23
23
  }
24
24
 
25
- pub(crate) fn u8(&mut self) -> Result<u8, DecodeError> {
25
+ pub(crate) fn read_u8(&mut self) -> Result<u8, DecodeError> {
26
26
  let byte = *self.bytes.get(self.pos).ok_or(MALFORMED)?;
27
27
  self.pos += 1;
28
28
  Ok(byte)
29
29
  }
30
30
 
31
- pub(crate) fn u32(&mut self) -> Result<u32, DecodeError> {
31
+ pub(crate) fn read_u32(&mut self) -> Result<u32, DecodeError> {
32
32
  let end = self.pos.checked_add(4).ok_or(MALFORMED)?;
33
33
  let slice = self.bytes.get(self.pos..end).ok_or(MALFORMED)?;
34
34
  self.pos = end;
@@ -37,8 +37,8 @@ impl<'a> Reader<'a> {
37
37
  }
38
38
 
39
39
  /// A `u32` length followed by that many bytes.
40
- pub(crate) fn bytes(&mut self) -> Result<&'a [u8], DecodeError> {
41
- let len = self.u32()? as usize;
40
+ pub(crate) fn read_bytes(&mut self) -> Result<&'a [u8], DecodeError> {
41
+ let len = self.read_u32()? as usize;
42
42
  let end = self.pos.checked_add(len).ok_or(MALFORMED)?;
43
43
  let slice = self.bytes.get(self.pos..end).ok_or(MALFORMED)?;
44
44
  self.pos = end;
@@ -48,9 +48,9 @@ impl<'a> Reader<'a> {
48
48
  /// A byte string carrying UTF-8. Every text field in the envelope is
49
49
  /// validated at decode so a frontend receives `&str` without repeating
50
50
  /// the check.
51
- pub(crate) fn text(&mut self) -> Result<&'a str, DecodeError> {
52
- core::str::from_utf8(self.bytes()?)
53
- .map_err(|_| DecodeError::new("core envelope text field is not valid UTF-8"))
51
+ pub(crate) fn read_text(&mut self) -> Result<&'a str, DecodeError> {
52
+ core::str::from_utf8(self.read_bytes()?)
53
+ .map_err(|_| DecodeError::new("Envelope text field is not valid UTF-8"))
54
54
  }
55
55
 
56
56
  /// A `u32` count followed by that many byte strings, each carrying
@@ -58,26 +58,37 @@ impl<'a> Reader<'a> {
58
58
  ///
59
59
  /// The elements are copied rather than borrowed: a binding's path and
60
60
  /// a panic's `available` names outlive the frame buffer they arrive in.
61
- pub(crate) fn text_list(&mut self) -> Result<Vec<String>, DecodeError> {
62
- self.list(|reader| Ok(reader.text()?.to_owned()))
61
+ pub(crate) fn read_text_list(&mut self) -> Result<Vec<String>, DecodeError> {
62
+ self.read_list(|reader| Ok(reader.read_text()?.to_owned()))
63
63
  }
64
64
 
65
65
  /// A `u32` count followed by that many byte strings of any content,
66
- /// copied for the same reason as `text_list`.
67
- pub(crate) fn bytes_list(&mut self) -> Result<Vec<Vec<u8>>, DecodeError> {
68
- self.list(|reader| Ok(reader.bytes()?.to_vec()))
66
+ /// copied for the same reason as `read_text_list`.
67
+ pub(crate) fn read_bytes_list(&mut self) -> Result<Vec<Vec<u8>>, DecodeError> {
68
+ self.read_list(|reader| Ok(reader.read_bytes()?.to_vec()))
69
69
  }
70
70
 
71
- fn list<T>(
71
+ /// A `u32` count of items each at least `min_len` bytes long. A count
72
+ /// past what the bytes left can hold can never be satisfied, so it is
73
+ /// refused with `too_many` before it sizes an allocation or bounds work.
74
+ pub(crate) fn read_count(
75
+ &mut self,
76
+ min_len: usize,
77
+ too_many: DecodeError,
78
+ ) -> Result<usize, DecodeError> {
79
+ let count = self.read_u32()? as usize;
80
+ if count > self.remaining().len() / min_len {
81
+ return Err(too_many);
82
+ }
83
+ Ok(count)
84
+ }
85
+
86
+ fn read_list<T>(
72
87
  &mut self,
73
88
  mut element: impl FnMut(&mut Self) -> Result<T, DecodeError>,
74
89
  ) -> Result<Vec<T>, DecodeError> {
75
- let count = self.u32()? as usize;
76
- // Every element opens with a `u32` length, so a count past what the
77
- // bytes left can hold is refused before it sizes the allocation.
78
- if count > self.remaining().len() / size_of::<u32>() {
79
- return Err(MALFORMED);
80
- }
90
+ // Every element opens with a `u32` length.
91
+ let count = self.read_count(size_of::<u32>(), MALFORMED)?;
81
92
  let mut out = Vec::with_capacity(count);
82
93
  for _ in 0..count {
83
94
  out.push(element(self)?);
@@ -106,7 +117,7 @@ impl<'a> Reader<'a> {
106
117
  Ok(())
107
118
  } else {
108
119
  Err(DecodeError::new(
109
- "core envelope carries bytes past its last field",
120
+ "Envelope carries bytes past its last field",
110
121
  ))
111
122
  }
112
123
  }
@@ -175,15 +186,23 @@ mod tests {
175
186
  let encoded = w.into_bytes();
176
187
 
177
188
  let mut r = Reader::new(&encoded);
178
- assert_eq!(r.u8(), Ok(7), "a u8 must round-trip through the writer");
179
- assert_eq!(r.u32(), Ok(0xdead_beef), "a u32 must round-trip big-endian");
180
189
  assert_eq!(
181
- r.bytes(),
190
+ r.read_u8(),
191
+ Ok(7),
192
+ "a u8 must round-trip through the writer"
193
+ );
194
+ assert_eq!(
195
+ r.read_u32(),
196
+ Ok(0xdead_beef),
197
+ "a u32 must round-trip big-endian"
198
+ );
199
+ assert_eq!(
200
+ r.read_bytes(),
182
201
  Ok(&b"kv"[..]),
183
202
  "a length-prefixed byte string must round-trip"
184
203
  );
185
204
  assert_eq!(
186
- r.text_list(),
205
+ r.read_text_list(),
187
206
  Ok(vec!["a".to_owned(), "bc".to_owned()]),
188
207
  "a counted list must round-trip element for element"
189
208
  );
@@ -213,7 +232,7 @@ mod tests {
213
232
  let bytes = [0, 0, 0, 8, b'h', b'i'];
214
233
  let mut r = Reader::new(&bytes);
215
234
  assert!(
216
- r.bytes().is_err(),
235
+ r.read_bytes().is_err(),
217
236
  "a byte string whose length overruns the message must be rejected, not truncated"
218
237
  );
219
238
  }
@@ -225,7 +244,7 @@ mod tests {
225
244
  let bytes = [0xff, 0xff, 0xff, 0xff];
226
245
  let mut r = Reader::new(&bytes);
227
246
  assert!(
228
- r.text_list().is_err(),
247
+ r.read_text_list().is_err(),
229
248
  "a list count the message cannot satisfy must be rejected before any allocation"
230
249
  );
231
250
  }
@@ -238,7 +257,7 @@ mod tests {
238
257
  let encoded = w.into_bytes();
239
258
  let mut r = Reader::new(&encoded);
240
259
  assert!(
241
- r.text().is_err(),
260
+ r.read_text().is_err(),
242
261
  "a text field carrying non-UTF-8 bytes must be rejected at decode"
243
262
  );
244
263
  }
@@ -250,7 +269,7 @@ mod tests {
250
269
  w.bytes(b"ok").remainder(b"!");
251
270
  let encoded = w.into_bytes();
252
271
  let mut r = Reader::new(&encoded);
253
- r.bytes().unwrap();
272
+ r.read_bytes().unwrap();
254
273
  assert!(
255
274
  r.finish().is_err(),
256
275
  "bytes past an envelope's last field must fail loudly as a framing desync"
@@ -13,6 +13,10 @@ use super::DecodeError;
13
13
  const KIND_PATH: u8 = 0;
14
14
  const KIND_HANDLE: u8 = 1;
15
15
 
16
+ /// The most a Capability Handle id may be: the wire pins ids to the positive
17
+ /// i32 range, so no table issues one past it and no side takes one.
18
+ pub const MAX_HANDLE_ID: u32 = 0x7fff_ffff;
19
+
16
20
  /// The object a Call is addressed to.
17
21
  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
18
22
  pub enum Target<'a> {
@@ -36,18 +40,26 @@ pub struct Call<'a> {
36
40
  impl<'a> Call<'a> {
37
41
  pub fn decode(bytes: &'a [u8]) -> Result<Self, DecodeError> {
38
42
  let mut reader = Reader::new(bytes);
39
- let target = match reader.u8()? {
40
- KIND_PATH => Target::Path(reader.text()?),
41
- KIND_HANDLE => Target::Handle(reader.u32()?),
43
+ let target = match reader.read_u8()? {
44
+ KIND_PATH => Target::Path(reader.read_text()?),
45
+ KIND_HANDLE => Target::Handle(reader.read_u32()?),
42
46
  _ => return Err(DecodeError::new("Call kind must be 0 (path) or 1 (handle)")),
43
47
  };
44
- if let Target::Handle(0) = target {
45
- return Err(DecodeError::new(
46
- "Call target Handle id 0 is the invalid sentinel",
47
- ));
48
+ match target {
49
+ Target::Handle(0) => {
50
+ return Err(DecodeError::new(
51
+ "Call target Handle id 0 is the invalid sentinel",
52
+ ))
53
+ }
54
+ Target::Handle(id) if id > MAX_HANDLE_ID => {
55
+ return Err(DecodeError::new(
56
+ "Call target Handle id must be at most 0x7fff_ffff",
57
+ ))
58
+ }
59
+ _ => {}
48
60
  }
49
- let method = reader.text()?;
50
- let block_given = match reader.u8()? {
61
+ let method = reader.read_text()?;
62
+ let block_given = match reader.read_u8()? {
51
63
  0 => false,
52
64
  1 => true,
53
65
  _ => return Err(DecodeError::new("Call block_given must be 0 or 1")),
@@ -205,6 +217,22 @@ mod tests {
205
217
  );
206
218
  }
207
219
 
220
+ // @behavior WE-091
221
+ #[test]
222
+ fn a_handle_id_past_the_wire_range_is_refused() {
223
+ let call_of = |id: u32| {
224
+ let mut w = Writer::new();
225
+ w.u8(KIND_HANDLE).u32(id).bytes(b"m").u8(0);
226
+ w.into_bytes()
227
+ };
228
+ assert!(
229
+ Call::decode(&call_of(0x7fff_ffff)).is_ok()
230
+ && Call::decode(&call_of(0x8000_0000)).is_err(),
231
+ "Call::decode must take a Handle id of 0x7fff_ffff in the target position and refuse \
232
+ 0x8000_0000"
233
+ );
234
+ }
235
+
208
236
  // @behavior WE-016
209
237
  #[test]
210
238
  fn a_non_boolean_block_flag_is_refused() {
@@ -20,9 +20,9 @@ pub enum CompileReply {
20
20
  impl CompileReply {
21
21
  pub fn decode(bytes: &[u8]) -> Result<Self, DecodeError> {
22
22
  let mut reader = Reader::new(bytes);
23
- match reader.u8()? {
23
+ match reader.read_u8()? {
24
24
  tag::OK => {
25
- let bytecodes = reader.bytes_list()?;
25
+ let bytecodes = reader.read_bytes_list()?;
26
26
  reader.finish()?;
27
27
  Ok(CompileReply::Ok(bytecodes))
28
28
  }
@@ -8,6 +8,27 @@
8
8
  use super::bytes::{Reader, Writer};
9
9
  use super::DecodeError;
10
10
 
11
+ /// The name a wire violation carries: an exchange that did not complete.
12
+ pub const TRANSPORT_ERROR: &str = "Kobako::Transport::Error";
13
+ /// The name a guest that could not start the Sandbox carries.
14
+ pub const BOOT_ERROR: &str = "Kobako::BootError";
15
+ /// The name a failure the guest's own flow detected carries, where no script
16
+ /// error names one.
17
+ pub const SANDBOX_ERROR: &str = "Kobako::SandboxError";
18
+ /// The name a Snippet the guest could not load carries.
19
+ pub const BYTECODE_ERROR: &str = "Kobako::BytecodeError";
20
+ /// The name a critical Preamble flag the guest does not know carries.
21
+ pub const UNSUPPORTED_FLAG_ERROR: &str = "Kobako::UnsupportedFlagError";
22
+ /// The name a Run whose entrypoint the guest cannot resolve carries.
23
+ pub const UNDEFINED_ENTRYPOINT_ERROR: &str = "Kobako::UndefinedEntrypointError";
24
+ /// The name a Service call that failed carries, where no Fault category
25
+ /// narrows it.
26
+ pub const SERVICE_ERROR: &str = "Kobako::ServiceError";
27
+ /// The name a call to a Service the host does not hold carries.
28
+ pub const NO_SERVICE_ERROR: &str = "Kobako::NoServiceError";
29
+ /// The name a Service call the host refused for its arguments carries.
30
+ pub const SERVICE_ARGUMENT_ERROR: &str = "Kobako::ServiceArgumentError";
31
+
11
32
  /// The error's name, message, and backtrace as the guest saw them. `name`
12
33
  /// rather than `class` because a guest need not be object-oriented to have
13
34
  /// named the error it is reporting.
@@ -21,9 +42,9 @@ pub struct ErrorRecord {
21
42
  impl ErrorRecord {
22
43
  pub(crate) fn read(reader: &mut Reader<'_>) -> Result<Self, DecodeError> {
23
44
  Ok(ErrorRecord {
24
- name: reader.text()?.to_owned(),
25
- message: reader.text()?.to_owned(),
26
- backtrace: reader.text_list()?,
45
+ name: reader.read_text()?.to_owned(),
46
+ message: reader.read_text()?.to_owned(),
47
+ backtrace: reader.read_text_list()?,
27
48
  })
28
49
  }
29
50
 
@@ -116,8 +116,8 @@ impl Fault {
116
116
  }
117
117
 
118
118
  pub(crate) fn read(reader: &mut Reader<'_>) -> Result<Self, DecodeError> {
119
- let kind = FaultKind::from_tag(reader.u8()?);
120
- let message = reader.text()?.to_owned();
119
+ let kind = FaultKind::from_tag(reader.read_u8()?);
120
+ let message = reader.read_text()?.to_owned();
121
121
  // A Fault gains fields as the contract does, and it is the last
122
122
  // thing a Reply carries, so whatever follows the fields this
123
123
  // reader knows belongs to a later version of them.
@@ -0,0 +1,99 @@
1
+ //! The form every name a guest interns takes: a Snippet's name, a Run's
2
+ //! entrypoint, and each segment of a Binding's path. The guest reaches each
3
+ //! one as a Ruby constant, so every side refuses one outside that form
4
+ //! before it is written.
5
+
6
+ /// The module the guest keeps for itself, where no Binding may stand.
7
+ pub const RESERVED_NAMESPACE: &str = "Kobako";
8
+
9
+ /// The guest interns every constant name, and mruby holds a symbol of at
10
+ /// most this many bytes.
11
+ const MAX_SYMBOL_LEN: usize = 65_534;
12
+
13
+ /// Whether `name` is a Ruby constant name the guest can intern: an ASCII
14
+ /// capital, then ASCII letters, digits, or `_`, within mruby's symbol length.
15
+ pub fn is_constant_name(name: &str) -> bool {
16
+ let mut chars = name.chars();
17
+ name.len() <= MAX_SYMBOL_LEN
18
+ && chars.next().is_some_and(|c| c.is_ascii_uppercase())
19
+ && chars.all(|c| c.is_ascii_alphanumeric() || c == '_')
20
+ }
21
+
22
+ /// Whether `path` is constant names joined by `::`.
23
+ pub fn is_constant_path(path: &str) -> bool {
24
+ path.split("::").all(is_constant_name)
25
+ }
26
+
27
+ /// Whether `path` stands in the guest's own `RESERVED_NAMESPACE`.
28
+ pub fn is_reserved(path: &str) -> bool {
29
+ path.split("::").next() == Some(RESERVED_NAMESPACE)
30
+ }
31
+
32
+ /// Whether `path` and `bound` cannot both be bound: they name one constant,
33
+ /// or one stands as the other's namespace, so the guest could not tell a
34
+ /// Service from a grouping module.
35
+ pub fn collides(path: &str, bound: &str) -> bool {
36
+ let within = |inner: &str, outer: &str| {
37
+ inner
38
+ .strip_prefix(outer)
39
+ .is_some_and(|rest| rest.starts_with("::"))
40
+ };
41
+ path == bound || within(path, bound) || within(bound, path)
42
+ }
43
+
44
+ #[cfg(test)]
45
+ mod tests {
46
+ use super::*;
47
+
48
+ #[test]
49
+ fn a_constant_name_is_an_ascii_capital_then_word_characters_within_a_symbol() {
50
+ let longest = format!("A{}", "b".repeat(MAX_SYMBOL_LEN - 1));
51
+ assert_eq!(
52
+ [
53
+ is_constant_name(&longest),
54
+ is_constant_name(&format!("{longest}b")),
55
+ is_constant_name("Aé"),
56
+ is_constant_name("A\n"),
57
+ is_constant_name("lower"),
58
+ is_constant_name(""),
59
+ ],
60
+ [true, false, false, false, false, false],
61
+ "is_constant_name must take an ASCII capital and word characters up to 65534 bytes, \
62
+ and refuse a longer name, a non-ASCII or newline character, a lowercase start, \
63
+ and an empty name"
64
+ );
65
+ }
66
+
67
+ #[test]
68
+ fn a_path_is_constant_names_joined_and_the_guests_own_namespace_is_reserved() {
69
+ assert_eq!(
70
+ [
71
+ is_constant_path("MyService::KV"),
72
+ is_constant_path("MyService::"),
73
+ is_constant_path("MyService:KV"),
74
+ is_reserved("Kobako"),
75
+ is_reserved("Kobako::KV"),
76
+ is_reserved("KobakoKV"),
77
+ ],
78
+ [true, false, false, true, true, false],
79
+ "is_constant_path must join constant names by '::' only, and is_reserved must hold \
80
+ a path whose first segment is Kobako and no other"
81
+ );
82
+ }
83
+
84
+ #[test]
85
+ fn a_path_collides_with_itself_and_with_either_side_of_a_namespace() {
86
+ assert_eq!(
87
+ [
88
+ collides("KV", "KV"),
89
+ collides("KV::Store", "KV"),
90
+ collides("KV", "KV::Store"),
91
+ collides("KVStore", "KV"),
92
+ collides("KV", "Cache"),
93
+ ],
94
+ [true, true, true, false, false],
95
+ "collides must hold for one path and for a path inside another's namespace, and \
96
+ not for a path that only shares a prefix"
97
+ );
98
+ }
99
+ }
@@ -11,9 +11,9 @@ use super::{tag, DecodeError, ErrorRecord, Unsupported};
11
11
  ///
12
12
  /// The wire field is an open set of byte strings, but only two values
13
13
  /// carry meaning — so both sides read and write it through this type and
14
- /// cannot come to spell either one differently. The fallback rule lives in
15
- /// `from_name`: an unrecognised value attributes to the sandbox rather
16
- /// than widening what a Service can claim.
14
+ /// cannot come to spell either one differently. An Outcome whose value no
15
+ /// origin spells attributes to the sandbox rather than widening what a
16
+ /// Service can claim.
17
17
  #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
18
18
  pub enum Origin {
19
19
  /// The guest script raised, or a boot step faulted.
@@ -32,12 +32,12 @@ impl Origin {
32
32
  }
33
33
  }
34
34
 
35
- /// Read a wire spelling back. Everything other than `"service"`,
36
- /// recognised or not, attributes to the sandbox.
37
- pub fn from_name(name: &str) -> Self {
35
+ /// Read a wire spelling back, `None` for one no origin spells.
36
+ pub(crate) fn from_name(name: &str) -> Option<Self> {
38
37
  match name {
39
- "service" => Origin::Service,
40
- _ => Origin::Sandbox,
38
+ "sandbox" => Some(Origin::Sandbox),
39
+ "service" => Some(Origin::Service),
40
+ _ => None,
41
41
  }
42
42
  }
43
43
  }
@@ -66,12 +66,12 @@ pub struct Panic {
66
66
  impl Outcome {
67
67
  pub fn decode(bytes: &[u8]) -> Result<Self, DecodeError> {
68
68
  let mut reader = Reader::new(bytes);
69
- match reader.u8()? {
69
+ match reader.read_u8()? {
70
70
  tag::OK => Ok(Outcome::Ok(reader.remaining().to_vec())),
71
71
  tag::PANIC => {
72
- let origin = Origin::from_name(reader.text()?);
72
+ let origin = Origin::from_name(reader.read_text()?).unwrap_or(Origin::Sandbox);
73
73
  let error = ErrorRecord::read(&mut reader)?;
74
- let available = reader.text_list()?;
74
+ let available = reader.read_text_list()?;
75
75
  reader.finish()?;
76
76
  Ok(Outcome::Panic(Panic {
77
77
  origin,
@@ -66,26 +66,22 @@ impl Preamble {
66
66
  /// appear at most once; an absent one reads as empty.
67
67
  pub fn decode(bytes: &[u8]) -> Result<Self, DecodeError> {
68
68
  let mut reader = Reader::new(bytes);
69
- let count = reader.u32()? as usize;
70
- // Each record costs at least six bytes, its two leading bytes and a
71
- // body length, so a count past the bytes left can never be
72
- // satisfied; refusing it bounds the work.
73
- if count > reader.remaining().len() {
74
- return Err(DecodeError::new(
75
- "Preamble declares more records than it holds",
76
- ));
77
- }
69
+ // Each record costs at least its two leading bytes and a body length.
70
+ let count = reader.read_count(
71
+ 2 + size_of::<u32>(),
72
+ DecodeError::new("Preamble declares more records than it holds"),
73
+ )?;
78
74
  let mut bindings = None;
79
75
  let mut snippets = None;
80
76
  let mut flags = Vec::new();
81
77
  for _ in 0..count {
82
- let critical = match reader.u8()? {
78
+ let critical = match reader.read_u8()? {
83
79
  ADVISORY => false,
84
80
  CRITICAL => true,
85
81
  _ => return Err(DecodeError::new("Preamble criticality must be 0 or 1")),
86
82
  };
87
- let kind = reader.u8()?;
88
- let body = reader.bytes()?;
83
+ let kind = reader.read_u8()?;
84
+ let body = reader.read_bytes()?;
89
85
  match kind {
90
86
  tag::BINDINGS => once(&mut bindings, decode_bindings(body)?)?,
91
87
  tag::SNIPPETS => once(&mut snippets, decode_snippets(body)?)?,
@@ -147,7 +143,7 @@ fn once<T>(slot: &mut Option<T>, value: T) -> Result<(), DecodeError> {
147
143
 
148
144
  fn decode_bindings(bytes: &[u8]) -> Result<Bindings, DecodeError> {
149
145
  let mut reader = Reader::new(bytes);
150
- let paths = reader.text_list()?;
146
+ let paths = reader.read_text_list()?;
151
147
  reader.finish()?;
152
148
  Ok(Bindings { paths })
153
149
  }
@@ -160,24 +156,20 @@ fn encode_bindings(bindings: &Bindings) -> Vec<u8> {
160
156
 
161
157
  fn decode_snippets(bytes: &[u8]) -> Result<Snippets, DecodeError> {
162
158
  let mut reader = Reader::new(bytes);
163
- let count = reader.u32()? as usize;
164
- // Each entry costs at least a kind byte and a `u32` length, so a count
165
- // past what the bytes left can hold is refused before it sizes the
166
- // allocation.
167
- if count > reader.remaining().len() / (1 + size_of::<u32>()) {
168
- return Err(DecodeError::new(
169
- "Preamble snippets declare more entries than they hold",
170
- ));
171
- }
159
+ // Each entry costs at least a kind byte and a `u32` length.
160
+ let count = reader.read_count(
161
+ 1 + size_of::<u32>(),
162
+ DecodeError::new("Preamble snippets declare more entries than they hold"),
163
+ )?;
172
164
  let mut entries = Vec::with_capacity(count);
173
165
  for _ in 0..count {
174
- entries.push(match reader.u8()? {
166
+ entries.push(match reader.read_u8()? {
175
167
  SNIPPET_SOURCE => Snippet::Source {
176
- name: reader.text()?.to_owned(),
177
- body: reader.text()?.to_owned(),
168
+ name: reader.read_text()?.to_owned(),
169
+ body: reader.read_text()?.to_owned(),
178
170
  },
179
171
  SNIPPET_BYTECODE => Snippet::Bytecode {
180
- body: reader.bytes()?.to_vec(),
172
+ body: reader.read_bytes()?.to_vec(),
181
173
  },
182
174
  _ => return Err(DecodeError::new("Preamble snippet kind must be 0 or 1")),
183
175
  });
@@ -207,8 +199,8 @@ fn encode_snippets(snippets: &Snippets) -> Vec<u8> {
207
199
 
208
200
  fn decode_flag(bytes: &[u8], critical: bool) -> Result<Flag, DecodeError> {
209
201
  let mut reader = Reader::new(bytes);
210
- let name = reader.text()?.to_owned();
211
- let value = reader.text()?.to_owned();
202
+ let name = reader.read_text()?.to_owned();
203
+ let value = reader.read_text()?.to_owned();
212
204
  reader.finish()?;
213
205
  Ok(Flag {
214
206
  name,
@@ -388,10 +380,21 @@ mod tests {
388
380
  fn a_count_the_preamble_cannot_satisfy_is_refused() {
389
381
  let records = [0xff, 0xff, 0xff, 0xff];
390
382
  let snippets = preamble_with(&[record(1, 0x06, &[0xff, 0xff, 0xff, 0xff])]);
391
- assert!(
392
- Preamble::decode(&records).is_err() && Preamble::decode(&snippets).is_err(),
383
+ // The count's own refusal, not a later read running out of bytes,
384
+ // is what shows nothing was taken for it.
385
+ let refusal = |bytes: &[u8]| {
386
+ Preamble::decode(bytes)
387
+ .err()
388
+ .map(|err| err.message().to_owned())
389
+ };
390
+ assert_eq!(
391
+ (refusal(&records), refusal(&snippets)),
392
+ (
393
+ Some("Preamble declares more records than it holds".to_owned()),
394
+ Some("Preamble snippets declare more entries than they hold".to_owned())
395
+ ),
393
396
  "a record or snippet count larger than what follows through Preamble::decode must \
394
- be refused before anything is allocated for it"
397
+ be refused for its count, before anything is allocated for it"
395
398
  );
396
399
  }
397
400