rugged 0.26.3 → 0.26.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +1 -1
  4. data/vendor/libgit2/deps/winhttp/winhttp.h +6 -4
  5. data/vendor/libgit2/deps/zlib/adler32.c +14 -7
  6. data/vendor/libgit2/deps/zlib/crc32.c +29 -12
  7. data/vendor/libgit2/deps/zlib/deflate.c +499 -303
  8. data/vendor/libgit2/deps/zlib/deflate.h +18 -15
  9. data/vendor/libgit2/deps/zlib/gzguts.h +218 -0
  10. data/vendor/libgit2/deps/zlib/infback.c +2 -2
  11. data/vendor/libgit2/deps/zlib/inffast.c +34 -51
  12. data/vendor/libgit2/deps/zlib/inflate.c +86 -37
  13. data/vendor/libgit2/deps/zlib/inflate.h +7 -4
  14. data/vendor/libgit2/deps/zlib/inftrees.c +12 -14
  15. data/vendor/libgit2/deps/zlib/trees.c +38 -61
  16. data/vendor/libgit2/deps/zlib/zconf.h +499 -23
  17. data/vendor/libgit2/deps/zlib/zlib.h +298 -154
  18. data/vendor/libgit2/deps/zlib/zutil.c +27 -23
  19. data/vendor/libgit2/deps/zlib/zutil.h +35 -17
  20. data/vendor/libgit2/include/git2.h +1 -0
  21. data/vendor/libgit2/include/git2/sys/mempack.h +5 -4
  22. data/vendor/libgit2/include/git2/version.h +2 -2
  23. data/vendor/libgit2/src/checkout.c +34 -11
  24. data/vendor/libgit2/src/curl_stream.c +21 -0
  25. data/vendor/libgit2/src/curl_stream.h +1 -0
  26. data/vendor/libgit2/src/delta.c +30 -28
  27. data/vendor/libgit2/src/diff.c +0 -7
  28. data/vendor/libgit2/src/diff_file.c +3 -1
  29. data/vendor/libgit2/src/diff_generate.c +1 -1
  30. data/vendor/libgit2/src/diff_tform.c +3 -1
  31. data/vendor/libgit2/src/global.c +4 -2
  32. data/vendor/libgit2/src/hash/hash_openssl.h +18 -3
  33. data/vendor/libgit2/src/ignore.c +60 -36
  34. data/vendor/libgit2/src/index.c +59 -26
  35. data/vendor/libgit2/src/indexer.c +15 -2
  36. data/vendor/libgit2/src/merge.c +18 -8
  37. data/vendor/libgit2/src/odb_mempack.c +1 -0
  38. data/vendor/libgit2/src/oidarray.c +12 -0
  39. data/vendor/libgit2/src/oidarray.h +1 -0
  40. data/vendor/libgit2/src/openssl_stream.c +17 -4
  41. data/vendor/libgit2/src/pack.c +10 -7
  42. data/vendor/libgit2/src/path.c +180 -22
  43. data/vendor/libgit2/src/path.h +73 -0
  44. data/vendor/libgit2/src/posix.c +1 -1
  45. data/vendor/libgit2/src/posix.h +3 -0
  46. data/vendor/libgit2/src/proxy.c +6 -0
  47. data/vendor/libgit2/src/proxy.h +1 -0
  48. data/vendor/libgit2/src/push.c +3 -0
  49. data/vendor/libgit2/src/refdb_fs.c +2 -2
  50. data/vendor/libgit2/src/refs.c +7 -1
  51. data/vendor/libgit2/src/repository.c +9 -3
  52. data/vendor/libgit2/src/sha1_lookup.c +2 -2
  53. data/vendor/libgit2/src/signature.c +1 -0
  54. data/vendor/libgit2/src/socket_stream.c +1 -1
  55. data/vendor/libgit2/src/stransport_stream.c +3 -1
  56. data/vendor/libgit2/src/submodule.c +54 -7
  57. data/vendor/libgit2/src/submodule.h +13 -0
  58. data/vendor/libgit2/src/transports/smart_pkt.c +8 -2
  59. data/vendor/libgit2/src/transports/smart_protocol.c +6 -6
  60. data/vendor/libgit2/src/transports/winhttp.c +22 -0
  61. data/vendor/libgit2/src/tree.c +1 -1
  62. metadata +3 -2
@@ -1,27 +1,27 @@
1
1
  /* zutil.c -- target dependent utility functions for the compression library
2
- * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
2
+ * Copyright (C) 1995-2017 Jean-loup Gailly
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
6
6
  /* @(#) $Id$ */
7
7
 
8
8
  #include "zutil.h"
9
-
10
- #ifndef NO_DUMMY_DECL
11
- struct internal_state {int dummy;}; /* for buggy compilers */
9
+ #ifndef Z_SOLO
10
+ # include "gzguts.h"
12
11
  #endif
13
12
 
14
13
  z_const char * const z_errmsg[10] = {
15
- "need dictionary", /* Z_NEED_DICT 2 */
16
- "stream end", /* Z_STREAM_END 1 */
17
- "", /* Z_OK 0 */
18
- "file error", /* Z_ERRNO (-1) */
19
- "stream error", /* Z_STREAM_ERROR (-2) */
20
- "data error", /* Z_DATA_ERROR (-3) */
21
- "insufficient memory", /* Z_MEM_ERROR (-4) */
22
- "buffer error", /* Z_BUF_ERROR (-5) */
23
- "incompatible version",/* Z_VERSION_ERROR (-6) */
24
- ""};
14
+ (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
15
+ (z_const char *)"stream end", /* Z_STREAM_END 1 */
16
+ (z_const char *)"", /* Z_OK 0 */
17
+ (z_const char *)"file error", /* Z_ERRNO (-1) */
18
+ (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
19
+ (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
20
+ (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
21
+ (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
22
+ (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
23
+ (z_const char *)""
24
+ };
25
25
 
26
26
 
27
27
  const char * ZEXPORT zlibVersion()
@@ -58,7 +58,7 @@ uLong ZEXPORT zlibCompileFlags()
58
58
  case 8: flags += 2 << 6; break;
59
59
  default: flags += 3 << 6;
60
60
  }
61
- #ifdef DEBUG
61
+ #ifdef ZLIB_DEBUG
62
62
  flags += 1 << 8;
63
63
  #endif
64
64
  #if defined(ASMV) || defined(ASMINF)
@@ -112,8 +112,8 @@ uLong ZEXPORT zlibCompileFlags()
112
112
  return flags;
113
113
  }
114
114
 
115
- #ifdef DEBUG
116
-
115
+ #ifdef ZLIB_DEBUG
116
+ #include <stdlib.h>
117
117
  # ifndef verbose
118
118
  # define verbose 0
119
119
  # endif
@@ -216,9 +216,11 @@ local ptr_table table[MAX_PTR];
216
216
 
217
217
  voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
218
218
  {
219
- voidpf buf = opaque; /* just to make some compilers happy */
219
+ voidpf buf;
220
220
  ulg bsize = (ulg)items*size;
221
221
 
222
+ (void)opaque;
223
+
222
224
  /* If we allocate less than 65520 bytes, we assume that farmalloc
223
225
  * will return a usable pointer which doesn't have to be normalized.
224
226
  */
@@ -241,6 +243,9 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
241
243
  void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
242
244
  {
243
245
  int n;
246
+
247
+ (void)opaque;
248
+
244
249
  if (*(ush*)&ptr != 0) { /* object < 64K */
245
250
  farfree(ptr);
246
251
  return;
@@ -256,7 +261,6 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
256
261
  next_ptr--;
257
262
  return;
258
263
  }
259
- ptr = opaque; /* just to make some compilers happy */
260
264
  Assert(0, "zcfree: ptr not found");
261
265
  }
262
266
 
@@ -275,13 +279,13 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
275
279
 
276
280
  voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
277
281
  {
278
- if (opaque) opaque = 0; /* to make compiler happy */
282
+ (void)opaque;
279
283
  return _halloc((long)items, size);
280
284
  }
281
285
 
282
286
  void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
283
287
  {
284
- if (opaque) opaque = 0; /* to make compiler happy */
288
+ (void)opaque;
285
289
  _hfree(ptr);
286
290
  }
287
291
 
@@ -303,7 +307,7 @@ voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
303
307
  unsigned items;
304
308
  unsigned size;
305
309
  {
306
- if (opaque) items += size - size; /* make compiler happy */
310
+ (void)opaque;
307
311
  return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
308
312
  (voidpf)calloc(items, size);
309
313
  }
@@ -312,8 +316,8 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
312
316
  voidpf opaque;
313
317
  voidpf ptr;
314
318
  {
319
+ (void)opaque;
315
320
  free(ptr);
316
- if (opaque) return; /* make compiler happy */
317
321
  }
318
322
 
319
323
  #endif /* MY_ZCALLOC */
@@ -1,5 +1,5 @@
1
1
  /* zutil.h -- internal interface and configuration of the compression library
2
- * Copyright (C) 1995-2013 Jean-loup Gailly.
2
+ * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -36,7 +36,9 @@
36
36
  #ifndef local
37
37
  # define local static
38
38
  #endif
39
- /* compile with -Dlocal if your debugger can't find static symbols */
39
+ /* since "static" is used to mean two completely different things in C, we
40
+ define "local" for the non-static meaning of "static", for readability
41
+ (compile with -Dlocal if your debugger can't find static symbols) */
40
42
 
41
43
  typedef unsigned char uch;
42
44
  typedef uch FAR uchf;
@@ -98,28 +100,38 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
98
100
  #endif
99
101
 
100
102
  #ifdef AMIGA
101
- # define OS_CODE 0x01
103
+ # define OS_CODE 1
102
104
  #endif
103
105
 
104
106
  #if defined(VAXC) || defined(VMS)
105
- # define OS_CODE 0x02
107
+ # define OS_CODE 2
106
108
  # define F_OPEN(name, mode) \
107
109
  fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
108
110
  #endif
109
111
 
112
+ #ifdef __370__
113
+ # if __TARGET_LIB__ < 0x20000000
114
+ # define OS_CODE 4
115
+ # elif __TARGET_LIB__ < 0x40000000
116
+ # define OS_CODE 11
117
+ # else
118
+ # define OS_CODE 8
119
+ # endif
120
+ #endif
121
+
110
122
  #if defined(ATARI) || defined(atarist)
111
- # define OS_CODE 0x05
123
+ # define OS_CODE 5
112
124
  #endif
113
125
 
114
126
  #ifdef OS2
115
- # define OS_CODE 0x06
127
+ # define OS_CODE 6
116
128
  # if defined(M_I86) && !defined(Z_SOLO)
117
129
  # include <malloc.h>
118
130
  # endif
119
131
  #endif
120
132
 
121
133
  #if defined(MACOS) || defined(TARGET_OS_MAC)
122
- # define OS_CODE 0x07
134
+ # define OS_CODE 7
123
135
  # ifndef Z_SOLO
124
136
  # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
125
137
  # include <unix.h> /* for fdopen */
@@ -131,18 +143,24 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
131
143
  # endif
132
144
  #endif
133
145
 
134
- #ifdef TOPS20
135
- # define OS_CODE 0x0a
146
+ #ifdef __acorn
147
+ # define OS_CODE 13
136
148
  #endif
137
149
 
138
- #ifdef WIN32
139
- # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
140
- # define OS_CODE 0x0b
141
- # endif
150
+ #if defined(WIN32) && !defined(__CYGWIN__)
151
+ # define OS_CODE 10
152
+ #endif
153
+
154
+ #ifdef _BEOS_
155
+ # define OS_CODE 16
156
+ #endif
157
+
158
+ #ifdef __TOS_OS400__
159
+ # define OS_CODE 18
142
160
  #endif
143
161
 
144
- #ifdef __50SERIES /* Prime/PRIMOS */
145
- # define OS_CODE 0x0f
162
+ #ifdef __APPLE__
163
+ # define OS_CODE 19
146
164
  #endif
147
165
 
148
166
  #if defined(_BEOS_) || defined(RISCOS)
@@ -177,7 +195,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
177
195
  /* common defaults */
178
196
 
179
197
  #ifndef OS_CODE
180
- # define OS_CODE 0x03 /* assume Unix */
198
+ # define OS_CODE 3 /* assume Unix */
181
199
  #endif
182
200
 
183
201
  #ifndef F_OPEN
@@ -216,7 +234,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
216
234
  #endif
217
235
 
218
236
  /* Diagnostic functions */
219
- #ifdef DEBUG
237
+ #ifdef ZLIB_DEBUG
220
238
  # include <stdio.h>
221
239
  extern int ZLIB_INTERNAL z_verbose;
222
240
  extern void ZLIB_INTERNAL z_error OF((char *m));
@@ -62,5 +62,6 @@
62
62
  #include "git2/tree.h"
63
63
  #include "git2/types.h"
64
64
  #include "git2/version.h"
65
+ #include "git2/worktree.h"
65
66
 
66
67
  #endif
@@ -11,6 +11,7 @@
11
11
  #include "git2/types.h"
12
12
  #include "git2/oid.h"
13
13
  #include "git2/odb.h"
14
+ #include "git2/buffer.h"
14
15
 
15
16
  /**
16
17
  * @file git2/sys/mempack.h
@@ -38,10 +39,10 @@ GIT_BEGIN_DECL
38
39
  * Subsequent reads will also be served from the in-memory store
39
40
  * to ensure consistency, until the memory store is dumped.
40
41
  *
41
- * @param out Poiter where to store the ODB backend
42
+ * @param out Pointer where to store the ODB backend
42
43
  * @return 0 on success; error code otherwise
43
44
  */
44
- int git_mempack_new(git_odb_backend **out);
45
+ GIT_EXTERN(int) git_mempack_new(git_odb_backend **out);
45
46
 
46
47
  /**
47
48
  * Dump all the queued in-memory writes to a packfile.
@@ -64,7 +65,7 @@ int git_mempack_new(git_odb_backend **out);
64
65
  * @param backend The mempack backend
65
66
  * @return 0 on success; error code otherwise
66
67
  */
67
- int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backend);
68
+ GIT_EXTERN(int) git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backend);
68
69
 
69
70
  /**
70
71
  * Reset the memory packer by clearing all the queued objects.
@@ -78,7 +79,7 @@ int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backe
78
79
  *
79
80
  * @param backend The mempack backend
80
81
  */
81
- void git_mempack_reset(git_odb_backend *backend);
82
+ GIT_EXTERN(void) git_mempack_reset(git_odb_backend *backend);
82
83
 
83
84
  GIT_END_DECL
84
85
 
@@ -7,10 +7,10 @@
7
7
  #ifndef INCLUDE_git_version_h__
8
8
  #define INCLUDE_git_version_h__
9
9
 
10
- #define LIBGIT2_VERSION "0.26.0"
10
+ #define LIBGIT2_VERSION "0.26.6"
11
11
  #define LIBGIT2_VER_MAJOR 0
12
12
  #define LIBGIT2_VER_MINOR 26
13
- #define LIBGIT2_VER_REVISION 0
13
+ #define LIBGIT2_VER_REVISION 6
14
14
  #define LIBGIT2_VER_PATCH 0
15
15
 
16
16
  #define LIBGIT2_SOVERSION 26
@@ -159,6 +159,19 @@ GIT_INLINE(bool) is_workdir_base_or_new(
159
159
  git_oid__cmp(&newitem->id, workdir_id) == 0);
160
160
  }
161
161
 
162
+ GIT_INLINE(bool) is_file_mode_changed(git_filemode_t a, git_filemode_t b)
163
+ {
164
+ #ifdef GIT_WIN32
165
+ /*
166
+ * On Win32 we do not support the executable bit; the file will
167
+ * always be 0100644 on disk, don't bother doing a test.
168
+ */
169
+ return false;
170
+ #else
171
+ return (S_ISREG(a) && S_ISREG(b) && a != b);
172
+ #endif
173
+ }
174
+
162
175
  static bool checkout_is_workdir_modified(
163
176
  checkout_data *data,
164
177
  const git_diff_file *baseitem,
@@ -192,16 +205,23 @@ static bool checkout_is_workdir_modified(
192
205
  return rval;
193
206
  }
194
207
 
195
- /* Look at the cache to decide if the workdir is modified. If not,
196
- * we can simply compare the oid in the cache to the baseitem instead
197
- * of hashing the file. If so, we allow the checkout to proceed if the
198
- * oid is identical (ie, the staged item is what we're trying to check
199
- * out.)
208
+ /*
209
+ * Look at the cache to decide if the workdir is modified: if the
210
+ * cache contents match the workdir contents, then we do not need
211
+ * to examine the working directory directly, instead we can
212
+ * examine the cache to see if _it_ has been modified. This allows
213
+ * us to avoid touching the disk.
200
214
  */
201
- if ((ie = git_index_get_bypath(data->index, wditem->path, 0)) != NULL) {
202
- if (git_index_time_eq(&wditem->mtime, &ie->mtime) &&
203
- wditem->file_size == ie->file_size)
204
- return !is_workdir_base_or_new(&ie->id, baseitem, newitem);
215
+ ie = git_index_get_bypath(data->index, wditem->path, 0);
216
+
217
+ if (ie != NULL &&
218
+ git_index_time_eq(&wditem->mtime, &ie->mtime) &&
219
+ wditem->file_size == ie->file_size &&
220
+ !is_file_mode_changed(wditem->mode, ie->mode)) {
221
+
222
+ /* The workdir is modified iff the index entry is modified */
223
+ return !is_workdir_base_or_new(&ie->id, baseitem, newitem) ||
224
+ is_file_mode_changed(baseitem->mode, ie->mode);
205
225
  }
206
226
 
207
227
  /* depending on where base is coming from, we may or may not know
@@ -214,6 +234,9 @@ static bool checkout_is_workdir_modified(
214
234
  if (S_ISDIR(wditem->mode))
215
235
  return false;
216
236
 
237
+ if (is_file_mode_changed(baseitem->mode, wditem->mode))
238
+ return true;
239
+
217
240
  if (git_diff__oid_for_entry(&oid, data->diff, wditem, wditem->mode, NULL) < 0)
218
241
  return false;
219
242
 
@@ -1249,14 +1272,14 @@ static int checkout_verify_paths(
1249
1272
  unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS;
1250
1273
 
1251
1274
  if (action & CHECKOUT_ACTION__REMOVE) {
1252
- if (!git_path_isvalid(repo, delta->old_file.path, flags)) {
1275
+ if (!git_path_isvalid(repo, delta->old_file.path, delta->old_file.mode, flags)) {
1253
1276
  giterr_set(GITERR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path);
1254
1277
  return -1;
1255
1278
  }
1256
1279
  }
1257
1280
 
1258
1281
  if (action & ~CHECKOUT_ACTION__REMOVE) {
1259
- if (!git_path_isvalid(repo, delta->new_file.path, flags)) {
1282
+ if (!git_path_isvalid(repo, delta->new_file.path, delta->new_file.mode, flags)) {
1260
1283
  giterr_set(GITERR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path);
1261
1284
  return -1;
1262
1285
  }
@@ -12,6 +12,7 @@
12
12
  #include "stream.h"
13
13
  #include "git2/transport.h"
14
14
  #include "buffer.h"
15
+ #include "global.h"
15
16
  #include "vector.h"
16
17
  #include "proxy.h"
17
18
 
@@ -36,6 +37,18 @@ typedef struct {
36
37
  git_cred *proxy_cred;
37
38
  } curl_stream;
38
39
 
40
+ int git_curl_stream_global_init(void)
41
+ {
42
+ if (curl_global_init(CURL_GLOBAL_ALL) != 0) {
43
+ giterr_set(GITERR_NET, "could not initialize curl");
44
+ return -1;
45
+ }
46
+
47
+ /* `curl_global_cleanup` is provided by libcurl */
48
+ git__on_shutdown(curl_global_cleanup);
49
+ return 0;
50
+ }
51
+
39
52
  static int seterr_curl(curl_stream *s)
40
53
  {
41
54
  giterr_set(GITERR_NET, "curl error: %s\n", s->curl_error);
@@ -193,6 +206,7 @@ static int curls_set_proxy(git_stream *stream, const git_proxy_options *proxy_op
193
206
  CURLcode res;
194
207
  curl_stream *s = (curl_stream *) stream;
195
208
 
209
+ git_proxy_options_clear(&s->proxy);
196
210
  if ((error = git_proxy_options_dup(&s->proxy, proxy_opts)) < 0)
197
211
  return error;
198
212
 
@@ -293,6 +307,8 @@ static void curls_free(git_stream *stream)
293
307
 
294
308
  curls_close(stream);
295
309
  git_strarray_free(&s->cert_info_strings);
310
+ git_proxy_options_clear(&s->proxy);
311
+ git_cred_free(s->proxy_cred);
296
312
  git__free(s);
297
313
  }
298
314
 
@@ -348,6 +364,11 @@ int git_curl_stream_new(git_stream **out, const char *host, const char *port)
348
364
 
349
365
  #include "stream.h"
350
366
 
367
+ int git_curl_stream_global_init(void)
368
+ {
369
+ return 0;
370
+ }
371
+
351
372
  int git_curl_stream_new(git_stream **out, const char *host, const char *port)
352
373
  {
353
374
  GIT_UNUSED(out);
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "git2/sys/stream.h"
11
11
 
12
+ extern int git_curl_stream_global_init(void);
12
13
  extern int git_curl_stream_new(git_stream **out, const char *host, const char *port);
13
14
 
14
15
  #endif
@@ -539,10 +539,11 @@ int git_delta_apply(
539
539
  *out = NULL;
540
540
  *out_len = 0;
541
541
 
542
- /* Check that the base size matches the data we were given;
543
- * if not we would underflow while accessing data from the
544
- * base object, resulting in data corruption or segfault.
545
- */
542
+ /*
543
+ * Check that the base size matches the data we were given;
544
+ * if not we would underflow while accessing data from the
545
+ * base object, resulting in data corruption or segfault.
546
+ */
546
547
  if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) {
547
548
  giterr_set(GITERR_INVALID, "failed to apply delta: base size does not match given data");
548
549
  return -1;
@@ -564,31 +565,34 @@ int git_delta_apply(
564
565
  while (delta < delta_end) {
565
566
  unsigned char cmd = *delta++;
566
567
  if (cmd & 0x80) {
567
- /* cmd is a copy instruction; copy from the base.
568
- */
569
- size_t off = 0, len = 0;
570
-
571
- if (cmd & 0x01) off = *delta++;
572
- if (cmd & 0x02) off |= *delta++ << 8UL;
573
- if (cmd & 0x04) off |= *delta++ << 16UL;
574
- if (cmd & 0x08) off |= *delta++ << 24UL;
575
-
576
- if (cmd & 0x10) len = *delta++;
577
- if (cmd & 0x20) len |= *delta++ << 8UL;
578
- if (cmd & 0x40) len |= *delta++ << 16UL;
579
- if (!len) len = 0x10000;
580
-
581
- if (base_len < off + len || res_sz < len)
568
+ /* cmd is a copy instruction; copy from the base. */
569
+ size_t off = 0, len = 0, end;
570
+
571
+ #define ADD_DELTA(o, shift) { if (delta < delta_end) (o) |= ((unsigned) *delta++ << shift); else goto fail; }
572
+ if (cmd & 0x01) ADD_DELTA(off, 0UL);
573
+ if (cmd & 0x02) ADD_DELTA(off, 8UL);
574
+ if (cmd & 0x04) ADD_DELTA(off, 16UL);
575
+ if (cmd & 0x08) ADD_DELTA(off, 24UL);
576
+
577
+ if (cmd & 0x10) ADD_DELTA(len, 0UL);
578
+ if (cmd & 0x20) ADD_DELTA(len, 8UL);
579
+ if (cmd & 0x40) ADD_DELTA(len, 16UL);
580
+ if (!len) len = 0x10000;
581
+ #undef ADD_DELTA
582
+
583
+ if (GIT_ADD_SIZET_OVERFLOW(&end, off, len) ||
584
+ base_len < end || res_sz < len)
582
585
  goto fail;
586
+
583
587
  memcpy(res_dp, base + off, len);
584
588
  res_dp += len;
585
589
  res_sz -= len;
586
590
 
587
- }
588
- else if (cmd) {
589
- /* cmd is a literal insert instruction; copy from
590
- * the delta stream itself.
591
- */
591
+ } else if (cmd) {
592
+ /*
593
+ * cmd is a literal insert instruction; copy from
594
+ * the delta stream itself.
595
+ */
592
596
  if (delta_end - delta < cmd || res_sz < cmd)
593
597
  goto fail;
594
598
  memcpy(res_dp, delta, cmd);
@@ -596,10 +600,8 @@ int git_delta_apply(
596
600
  res_dp += cmd;
597
601
  res_sz -= cmd;
598
602
 
599
- }
600
- else {
601
- /* cmd == 0 is reserved for future encodings.
602
- */
603
+ } else {
604
+ /* cmd == 0 is reserved for future encodings. */
603
605
  goto fail;
604
606
  }
605
607
  }