Merge lp:~gz/bzr/avoid_diff_delta_empty_malloc_856731 into lp:bzr/2.4

Proposed by Martin Packman
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6049
Proposed branch: lp:~gz/bzr/avoid_diff_delta_empty_malloc_856731
Merge into: lp:bzr/2.4
Diff against target: 29 lines (+9/-0)
2 files modified
bzrlib/diff-delta.c (+5/-0)
doc/en/release-notes/bzr-2.4.txt (+4/-0)
To merge this branch: bzr merge lp:~gz/bzr/avoid_diff_delta_empty_malloc_856731
Reviewer Review Type Date Requested Status
Martin Pool Approve
John A Meinel Approve
Review via email: mp+77737@code.launchpad.net

Commit message

Bug #856731, avoid calling malloc(0) for platforms that return NULL (such as AIX)

Description of the change

Very simple fix from John to avoid quirks with doing malloc(0) on some platforms.

I tested faking out that call point to behave in the funky manner reported, and running `bzr selftest -s bt.test_groupcompress` starts failing pretty hard, so there's clearly coverage for this problem on platforms where it can occur.

The bug was reported against 2.2 but I think 2.4 is far enough to go back, even with a change this minimal.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

I'm fine with this change, but it would be nice to actually run it on AIX to make sure it works as expected.

We should also audit to see if there are any other malloc(0) cases.

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

> I'm fine with this change, but it would be nice to actually run it on AIX to
> make sure it works as expected.

I agree. I'll ask the bug reporter.

> We should also audit to see if there are any other malloc(0) cases.

Forgot to mention in the description, I went through diff-delta.c and this was the only possible one (it's not the only point to multiply by some value without also adding a sizeof(something) but it's the only one where malloc(0) can actually result).

Revision history for this message
John A Meinel (jameinel) wrote :

sent to pqm by email

Revision history for this message
Martin Pool (mbp) wrote :

Could be worth getting it checked by John too, but

  review approve

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/5/2011 3:25 AM, Martin Pool wrote:
> Review: Approve
>
> Could be worth getting it checked by John too, but
>
> review approve
>

Yeah, I was happy with it, and submitted it.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6MEjIACgkQJdeBCYSNAAN1KACgj0ICUO4r+YT40w28N81hAiIQ
I4oAn1jRFxATQccAHzA3jF8TKPiP563m
=tMN2
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/diff-delta.c'
2--- bzrlib/diff-delta.c 2011-05-16 14:26:54 +0000
3+++ bzrlib/diff-delta.c 2011-09-30 16:46:02 +0000
4@@ -720,6 +720,11 @@
5
6 max_num_entries = (src->size - 1) / RABIN_WINDOW;
7
8+ if (!max_num_entries) {
9+ *fresh = old_index;
10+ return DELTA_OK;
11+ }
12+
13 /* allocate an array to hold whatever entries we find */
14 entries = malloc(sizeof(*entry) * max_num_entries);
15 if (!entries) /* malloc failure */
16
17=== modified file 'doc/en/release-notes/bzr-2.4.txt'
18--- doc/en/release-notes/bzr-2.4.txt 2011-09-29 14:58:56 +0000
19+++ doc/en/release-notes/bzr-2.4.txt 2011-09-30 16:46:02 +0000
20@@ -39,6 +39,10 @@
21 stat fields into four bytes in dirstate pack_stat implementations.
22 (Martin Packman, #683191 #706957)
23
24+* Return early from create_delta_index_from_delta given tiny inputs. This
25+ avoids raising a spurious MemoryError on certain platforms such as AIX.
26+ (John Arbash Meinel, #856731)
27+
28 Documentation
29 *************
30

Subscribers

People subscribed via source and target branches