* parse_loose_header() parses the starting " \0" of an * object. If it doesn't follow that format -1 is returned. To check * the validity of the populate the "typep" in the "struct * object_info". It will be OBJ_BAD if the object type is unknown. The * parsed can be retrieved via "oi->sizep", and from there * passed to unpack_loose_rest(). * * We used to just use "ss
| 260 | * object header parse by hand. |
| 261 | */ |
| 262 | int parse_loose_header(const char *hdr, struct object_info *oi) |
| 263 | { |
| 264 | const char *type_buf = hdr; |
| 265 | size_t size; |
| 266 | int type, type_len = 0; |
| 267 | |
| 268 | /* |
| 269 | * The type can be of any size but is followed by |
| 270 | * a space. |
| 271 | */ |
| 272 | for (;;) { |
| 273 | char c = *hdr++; |
| 274 | if (!c) |
| 275 | return -1; |
| 276 | if (c == ' ') |
| 277 | break; |
| 278 | type_len++; |
| 279 | } |
| 280 | |
| 281 | type = type_from_string_gently(type_buf, type_len, 1); |
| 282 | if (oi->typep) |
| 283 | *oi->typep = type; |
| 284 | |
| 285 | /* |
| 286 | * The length must follow immediately, and be in canonical |
| 287 | * decimal format (ie "010" is not valid). |
| 288 | */ |
| 289 | size = *hdr++ - '0'; |
| 290 | if (size > 9) |
| 291 | return -1; |
| 292 | if (size) { |
| 293 | for (;;) { |
| 294 | unsigned long c = *hdr - '0'; |
| 295 | if (c > 9) |
| 296 | break; |
| 297 | hdr++; |
| 298 | size = st_add(st_mult(size, 10), c); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | if (oi->sizep) |
| 303 | *oi->sizep = size; |
| 304 | |
| 305 | /* |
| 306 | * The length must be followed by a zero byte |
| 307 | */ |
| 308 | if (*hdr) |
| 309 | return -1; |
| 310 | |
| 311 | /* |
| 312 | * The format is valid, but the type may still be bogus. The |
| 313 | * Caller needs to check its oi->typep. |
| 314 | */ |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c, |
| 319 | const void *buf, unsigned long len, |
no test coverage detected