* Read a binary hunk and return a new fragment; fragment->patch * points at an allocated memory that the caller must free, so * it is marked as "->free_patch = 1". */
| 2016 | * it is marked as "->free_patch = 1". |
| 2017 | */ |
| 2018 | static struct fragment *parse_binary_hunk(struct apply_state *state, |
| 2019 | char **buf_p, |
| 2020 | unsigned long *sz_p, |
| 2021 | int *status_p, |
| 2022 | int *used_p) |
| 2023 | { |
| 2024 | /* |
| 2025 | * Expect a line that begins with binary patch method ("literal" |
| 2026 | * or "delta"), followed by the length of data before deflating. |
| 2027 | * a sequence of 'length-byte' followed by base-85 encoded data |
| 2028 | * should follow, terminated by a newline. |
| 2029 | * |
| 2030 | * Each 5-byte sequence of base-85 encodes up to 4 bytes, |
| 2031 | * and we would limit the patch line to 66 characters, |
| 2032 | * so one line can fit up to 13 groups that would decode |
| 2033 | * to 52 bytes max. The length byte 'A'-'Z' corresponds |
| 2034 | * to 1-26 bytes, and 'a'-'z' corresponds to 27-52 bytes. |
| 2035 | */ |
| 2036 | int llen, used; |
| 2037 | unsigned long size = *sz_p; |
| 2038 | char *buffer = *buf_p; |
| 2039 | int patch_method; |
| 2040 | unsigned long origlen; |
| 2041 | char *data = NULL; |
| 2042 | int hunk_size = 0; |
| 2043 | struct fragment *frag; |
| 2044 | |
| 2045 | llen = linelen(buffer, size); |
| 2046 | used = llen; |
| 2047 | |
| 2048 | *status_p = 0; |
| 2049 | |
| 2050 | if (starts_with(buffer, "delta ")) { |
| 2051 | patch_method = BINARY_DELTA_DEFLATED; |
| 2052 | origlen = strtoul(buffer + 6, NULL, 10); |
| 2053 | } |
| 2054 | else if (starts_with(buffer, "literal ")) { |
| 2055 | patch_method = BINARY_LITERAL_DEFLATED; |
| 2056 | origlen = strtoul(buffer + 8, NULL, 10); |
| 2057 | } |
| 2058 | else |
| 2059 | return NULL; |
| 2060 | |
| 2061 | state->linenr++; |
| 2062 | buffer += llen; |
| 2063 | size -= llen; |
| 2064 | while (1) { |
| 2065 | int byte_length, max_byte_length, newsize; |
| 2066 | llen = linelen(buffer, size); |
| 2067 | used += llen; |
| 2068 | state->linenr++; |
| 2069 | if (llen == 1) { |
| 2070 | /* consume the blank line */ |
| 2071 | buffer++; |
| 2072 | size--; |
| 2073 | break; |
| 2074 | } |
| 2075 | /* |
no test coverage detected