All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matt Cooper via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Carlo Arenas <carenas@gmail.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Matt Cooper <vtbassmatt@gmail.com>
Subject: [PATCH v3 5/8] odb: teach read_blob_entry to use size_t
Date: Fri, 29 Oct 2021 13:59:16 +0000	[thread overview]
Message-ID: <dbef8168bc7044dbc8471c5ecc7146cf3e979263.1635515959.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1068.v3.git.1635515959.gitgitgadget@gmail.com>

From: Matt Cooper <vtbassmatt@gmail.com>

There is mixed use of size_t and unsigned long to deal with sizes in the
codebase. Recall that Windows defines unsigned long as 32 bits even on
64-bit platforms, meaning that converting size_t to unsigned long narrows
the range. This mostly doesn't cause a problem since Git rarely deals
with files larger than 2^32 bytes.

But adjunct systems such as Git LFS, which use smudge/clean filters to
keep huge files out of the repository, may have huge file contents passed
through some of the functions in entry.c and convert.c. On Windows, this
results in a truncated file being written to the workdir. I traced this to
one specific use of unsigned long in write_entry (and a similar instance
in write_pc_item_to_fd for parallel checkout). That appeared to be for
the call to read_blob_entry, which expects a pointer to unsigned long.

By altering the signature of read_blob_entry to expect a size_t,
write_entry can be switched to use size_t internally (which all of its
callers and most of its callees already used). To avoid touching dozens of
additional files, read_blob_entry uses a local unsigned long to call a
chain of functions which aren't prepared to accept size_t.

Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Matt Cooper <vtbassmatt@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 entry.c                     | 8 +++++---
 entry.h                     | 2 +-
 parallel-checkout.c         | 2 +-
 t/t1051-large-conversion.sh | 2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/entry.c b/entry.c
index 711ee0693c7..4cb3942dbdc 100644
--- a/entry.c
+++ b/entry.c
@@ -82,11 +82,13 @@ static int create_file(const char *path, unsigned int mode)
 	return open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
 }
 
-void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
+void *read_blob_entry(const struct cache_entry *ce, size_t *size)
 {
 	enum object_type type;
-	void *blob_data = read_object_file(&ce->oid, &type, size);
+	unsigned long ul;
+	void *blob_data = read_object_file(&ce->oid, &type, &ul);
 
+	*size = ul;
 	if (blob_data) {
 		if (type == OBJ_BLOB)
 			return blob_data;
@@ -270,7 +272,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
 	int fd, ret, fstat_done = 0;
 	char *new_blob;
 	struct strbuf buf = STRBUF_INIT;
-	unsigned long size;
+	size_t size;
 	ssize_t wrote;
 	size_t newsize = 0;
 	struct stat st;
diff --git a/entry.h b/entry.h
index b8c0e170dc7..61ee8c17604 100644
--- a/entry.h
+++ b/entry.h
@@ -51,7 +51,7 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
  */
 void unlink_entry(const struct cache_entry *ce);
 
-void *read_blob_entry(const struct cache_entry *ce, unsigned long *size);
+void *read_blob_entry(const struct cache_entry *ce, size_t *size);
 int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st);
 void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
 			   struct stat *st);
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 6b1af32bb3d..b6f4a25642e 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -261,7 +261,7 @@ static int write_pc_item_to_fd(struct parallel_checkout_item *pc_item, int fd,
 	struct stream_filter *filter;
 	struct strbuf buf = STRBUF_INIT;
 	char *blob;
-	unsigned long size;
+	size_t size;
 	ssize_t wrote;
 
 	/* Sanity check */
diff --git a/t/t1051-large-conversion.sh b/t/t1051-large-conversion.sh
index bff86c13208..8b23d862600 100755
--- a/t/t1051-large-conversion.sh
+++ b/t/t1051-large-conversion.sh
@@ -85,7 +85,7 @@ test_expect_success 'ident converts on output' '
 
 # This smudge filter prepends 5GB of zeros to the file it checks out. This
 # ensures that smudging doesn't mangle large files on 64-bit Windows.
-test_expect_failure EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
+test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
 		'files over 4GB convert on output' '
 	test_commit test small "a small file" &&
 	test_config filter.makelarge.smudge \
-- 
gitgitgadget


  parent reply	other threads:[~2021-10-29 13:59 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27  7:49 [PATCH 0/5] Allow clean/smudge filters to handle huge files in the LLP64 data model Johannes Schindelin via GitGitGadget
2021-10-27  7:49 ` [PATCH 1/5] t1051: introduce a smudge filter test for extremely large files Matt Cooper via GitGitGadget
2021-10-28  7:15   ` Carlo Arenas
2021-10-28  8:54     ` [PATCH] helper/test-genzeros: allow more than 2G zeros in Windows Carlo Marcelo Arenas Belón
2021-10-28 20:32       ` Johannes Schindelin
2021-10-27  7:49 ` [PATCH 2/5] odb: teach read_blob_entry to use size_t Matt Cooper via GitGitGadget
2021-10-27  7:49 ` [PATCH 3/5] git-compat-util: introduce more size_t helpers Johannes Schindelin via GitGitGadget
2021-10-27  7:49 ` [PATCH 4/5] odb: guard against data loss checking out a huge file Matt Cooper via GitGitGadget
2021-10-27  7:49 ` [PATCH 5/5] clean/smudge: allow clean filters to process extremely large files Matt Cooper via GitGitGadget
2021-10-28 20:50 ` [PATCH v2 0/7] Allow clean/smudge filters to handle huge files in the LLP64 data model Johannes Schindelin via GitGitGadget
2021-10-28 20:50   ` [PATCH v2 1/7] test-genzeros: allow more than 2G zeros in Windows Carlo Marcelo Arenas Belón via GitGitGadget
2021-10-28 20:50   ` [PATCH v2 2/7] test-tool genzeros: generate large amounts of data more efficiently Johannes Schindelin via GitGitGadget
2021-10-28 22:55     ` Junio C Hamano
2021-10-28 20:50   ` [PATCH v2 3/7] t1051: introduce a smudge filter test for extremely large files Matt Cooper via GitGitGadget
2021-10-28 20:50   ` [PATCH v2 4/7] odb: teach read_blob_entry to use size_t Matt Cooper via GitGitGadget
2021-10-28 22:14     ` Carlo Arenas
2021-10-28 22:21       ` Johannes Schindelin
2021-10-28 20:50   ` [PATCH v2 5/7] git-compat-util: introduce more size_t helpers Johannes Schindelin via GitGitGadget
2021-10-28 23:05     ` Junio C Hamano
2021-10-28 20:50   ` [PATCH v2 6/7] odb: guard against data loss checking out a huge file Matt Cooper via GitGitGadget
2021-10-28 20:50   ` [PATCH v2 7/7] clean/smudge: allow clean filters to process extremely large files Matt Cooper via GitGitGadget
2021-10-28 22:32   ` [PATCH v2 0/7] Allow clean/smudge filters to handle huge files in the LLP64 data model brian m. carlson
2021-10-28 23:07     ` Junio C Hamano
2021-10-29 13:59   ` [PATCH v3 0/8] " Johannes Schindelin via GitGitGadget
2021-10-29 13:59     ` [PATCH v3 1/8] test-genzeros: allow more than 2G zeros in Windows Carlo Marcelo Arenas Belón via GitGitGadget
2021-10-29 13:59     ` [PATCH v3 2/8] test-tool genzeros: generate large amounts of data more efficiently Johannes Schindelin via GitGitGadget
2021-10-29 22:50       ` Junio C Hamano
2021-10-29 13:59     ` [PATCH v3 3/8] test-lib: add prerequisite for 64-bit platforms Carlo Marcelo Arenas Belón via GitGitGadget
2021-10-29 22:52       ` Junio C Hamano
2021-11-02 14:35         ` Johannes Schindelin
2021-10-29 13:59     ` [PATCH v3 4/8] t1051: introduce a smudge filter test for extremely large files Matt Cooper via GitGitGadget
2021-10-29 23:00       ` Junio C Hamano
2021-10-29 23:21         ` Junio C Hamano
2021-11-02 14:56           ` Johannes Schindelin
2021-11-02 14:57         ` Johannes Schindelin
2021-10-29 13:59     ` Matt Cooper via GitGitGadget [this message]
2021-10-29 23:17       ` [PATCH v3 5/8] odb: teach read_blob_entry to use size_t Junio C Hamano
2021-11-02 15:10         ` Johannes Schindelin
2021-10-29 13:59     ` [PATCH v3 6/8] git-compat-util: introduce more size_t helpers Johannes Schindelin via GitGitGadget
2021-10-29 23:10       ` Junio C Hamano
2021-10-29 13:59     ` [PATCH v3 7/8] odb: guard against data loss checking out a huge file Matt Cooper via GitGitGadget
2021-10-29 23:13       ` Junio C Hamano
2021-10-29 13:59     ` [PATCH v3 8/8] clean/smudge: allow clean filters to process extremely large files Matt Cooper via GitGitGadget
2021-10-29 23:17       ` Junio C Hamano
2021-11-02 14:59         ` Johannes Schindelin
2021-10-29 18:34     ` [PATCH v3 0/8] Allow clean/smudge filters to handle huge files in the LLP64 data model Junio C Hamano
     [not found]       ` <nycvar.QRO.7.76.6.2110292239170.56@tvgsbejvaqbjf.bet>
2021-10-29 21:12         ` Johannes Schindelin
2021-10-29 23:25           ` Junio C Hamano
2021-10-30 15:16           ` Philip Oakley
2021-10-30 17:35             ` Torsten Bögershausen
2021-10-30 19:29               ` Philip Oakley
2021-11-02 14:41       ` Johannes Schindelin
2021-11-02 15:46     ` [PATCH v4 " Johannes Schindelin via GitGitGadget
2021-11-02 15:46       ` [PATCH v4 1/8] test-genzeros: allow more than 2G zeros in Windows Carlo Marcelo Arenas Belón via GitGitGadget
2021-11-02 15:46       ` [PATCH v4 2/8] test-tool genzeros: generate large amounts of data more efficiently Johannes Schindelin via GitGitGadget
2021-11-02 15:46       ` [PATCH v4 3/8] test-lib: add prerequisite for 64-bit platforms Carlo Marcelo Arenas Belón via GitGitGadget
2021-11-02 15:46       ` [PATCH v4 4/8] t1051: introduce a smudge filter test for extremely large files Matt Cooper via GitGitGadget
2021-11-02 15:46       ` [PATCH v4 5/8] odb: teach read_blob_entry to use size_t Matt Cooper via GitGitGadget
2021-11-02 20:40         ` Torsten Bögershausen
2021-11-04  0:09           ` Johannes Schindelin
2021-11-04 12:24             ` Philip Oakley
2021-11-02 15:46       ` [PATCH v4 6/8] git-compat-util: introduce more size_t helpers Johannes Schindelin via GitGitGadget
2021-11-02 15:46       ` [PATCH v4 7/8] odb: guard against data loss checking out a huge file Matt Cooper via GitGitGadget
2021-11-02 15:46       ` [PATCH v4 8/8] clean/smudge: allow clean filters to process extremely large files Matt Cooper via GitGitGadget
2021-11-02 20:47         ` Torsten Bögershausen
2021-11-04  0:11           ` Johannes Schindelin
2021-11-04  8:33             ` Torsten Bögershausen
2021-11-04 17:26         ` Junio C Hamano
2021-11-02 21:46       ` [PATCH v4 0/8] Allow clean/smudge filters to handle huge files in the LLP64 data model Torsten Bögershausen
2021-11-03  6:31         ` Johannes Sixt
2021-10-28 20:56 ` [PATCH 0/3] " Carlo Marcelo Arenas Belón
2021-10-28 20:56   ` [PATCH 1/3] test-lib: add prerequisite for 64-bit platforms Carlo Marcelo Arenas Belón
2021-10-28 21:45     ` Johannes Schindelin
2021-10-28 22:09       ` Carlo Arenas
2021-10-28 22:38         ` Junio C Hamano
2021-11-02 15:20           ` Johannes Schindelin
2021-10-28 20:56   ` [PATCH 2/3] fixup! t1051: introduce a smudge filter test for extremely large files Carlo Marcelo Arenas Belón
2021-10-28 20:56   ` [PATCH 3/3] fixup! clean/smudge: allow clean filters to process " Carlo Marcelo Arenas Belón

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dbef8168bc7044dbc8471c5ecc7146cf3e979263.1635515959.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=sandals@crustytoothpaste.net \
    --cc=vtbassmatt@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.