edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! What a container header claims is untrusted input, and the numbers it |
| 2 | //! claims them with reach every raster this engine sizes. |
| 3 | //! |
| 4 | //! An mp4 `pasp` box is eight bytes: two 32-bit big-endian integers, the ratio |
| 5 | //! one coded pixel is drawn at. Nothing in the file makes them sane. Four |
| 6 | //! chosen bytes are enough to make the probe report a zero width, or a width |
| 7 | //! that wrapped a `u32` on its way down from the multiply -- and both of those |
| 8 | //! go straight into the `resize` that sizes the decode worker's stretched |
| 9 | //! planes, before a single pixel is drawn. |
| 10 | //! |
| 11 | //! This test byte-patches a copy of the baseline fixture and opens it through |
| 12 | //! the ordinary door: the patched files live in a temp directory and are made |
| 13 | //! here, so no hostile bytes are committed to the repository. |
| 14 | //! |
| 15 | //! ```text |
| 16 | //! cargo test -p engine --test untrusted_header -- --test-threads=1 |
| 17 | //! ``` |
| 18 | |
| 19 | use ; |
| 20 | |
| 21 | use Demuxer; |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | /// A temp directory that cleans itself up, so a failing test does not leave a |
| 30 | /// hostile mp4 lying around for the next one to trip over. |
| 31 | ; |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | /// A copy of `source` with the eight bytes of its `pasp` payload replaced. |
| 53 | /// |
| 54 | /// Returns the byte offset the payload was written at, so the test can name |
| 55 | /// the exact bytes it changed rather than asserting about a file whose |
| 56 | /// provenance is a fixture somebody might regenerate. |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | /// The claims an mp4 can make about its pixels that are not a picture: a zero |
| 72 | /// half, which divides to nothing, and a huge half, whose multiply wraps a |
| 73 | /// `u32` on the way down. |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | /// The half that matters is not the probe: it is the worker that sizes its |
| 137 | /// stretched planes from the same number. A decode that used to abort on a |
| 138 | /// capacity overflow here now returns the coded picture. |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | /// The same bound, on the other door. An mp4 states its picture in a visual |
| 165 | /// sample entry's two `u16` fields -- a smaller claim than Matroska's EBML |
| 166 | /// integer, but still eight times past the 8K ceiling, and it reaches the same |
| 167 | /// `decode.rs` allocation. |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | /// A copy of `source` with the width and height of its first visual sample |
| 189 | /// entry set to `w`/`h` (ISO/IEC 14496-12 §12.1.3: two 16-bit fields, 24 |
| 190 | /// bytes into the entry, after the 6 reserved bytes, the 2-byte data |
| 191 | /// reference index and the 16 bytes of pre-defined and reserved fields). |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | /// The boundary of the bound, stated as a test rather than left as a surprise: |
| 210 | /// 7680 -- 8K UHD -- opens, and 8192 -- 8K DCI, a real ProRes 4444 XQ master |
| 211 | /// width -- is refused by name. |
| 212 | /// |
| 213 | /// The refusal of a DCI-width master is a behaviour change this lane |
| 214 | /// introduced: before it, the bound was asked only of a keystroke and a |
| 215 | /// `.edith` line, never of a file's own header, so a container could state any |
| 216 | /// size at all. `MAX_RESOLUTION` stays 7680 rather than being raised to 8192, |
| 217 | /// because it gates those two doors at 7680 too and widening the ceiling on |
| 218 | /// every path to accommodate a container is a wider decision than a header fix |
| 219 | /// should make. |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 |