| 138 | |
| 139 | |
| 140 | def native_log(destination, record): |
| 141 | require(isinstance(record, dict) and isinstance(record.get("path"), str) |
| 142 | and "capture" in record, "native capture log metadata") |
| 143 | path = Path(record["path"]) |
| 144 | require(path.is_absolute(), "native capture path must be absolute") |
| 145 | try: |
| 146 | relative = path.relative_to(destination) |
| 147 | except ValueError as exc: |
| 148 | raise Regression("native capture path escaped owned bundle") from exc |
| 149 | require(relative.parts and ".." not in relative.parts, "native capture path traversal") |
| 150 | current = destination |
| 151 | for part in relative.parts: |
| 152 | current = current / part |
| 153 | require(not current.is_symlink(), "native capture path contains symlink") |
| 154 | data = read(path, 32 * 1024 * 1024) |
| 155 | require(type(record.get("bytes")) is int and record["bytes"] == len(data) |
| 156 | and record.get("sha256") == digest(path), "native capture length/digest mismatch") |
| 157 | return data |
| 158 | |
| 159 | |
| 160 | def retained_profiles(destination): |