Skip to content

pass pointers straight through 'git lfs clean' - #271

Merged
technoweenie merged 2 commits into
masterfrom
dont-clean-pointers
Apr 29, 2015
Merged

technoweenie merged 2 commits into
masterfrom
dont-clean-pointers

Conversation

@technoweenie

Copy link
Copy Markdown
Contributor

This teaches git lfs clean to pass Git LFS pointers straight through. There's no point in saving a pointer of a pointer.

@technoweenie technoweenie mentioned this pull request Apr 28, 2015
17 tasks done
@technoweenie

Copy link
Copy Markdown
Contributor Author

@rubyist: Sorry, this is probably going to cause some fun merge conflicts with #258.

@rubyist

rubyist commented Apr 29, 2015

Copy link
Copy Markdown
Contributor

-merge coooooooooonflicts

👍

technoweenie added a commit that referenced this pull request Apr 29, 2015
pass pointers straight through 'git lfs clean'
@technoweenie
technoweenie merged commit 3321ccc into master Apr 29, 2015
@technoweenie
technoweenie deleted the dont-clean-pointers branch April 29, 2015 15:32
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 11, 2021
When the "clean" filter processes a pre-existing LFS pointer
blob, the copyToTemp() function returns a CleanPointerError;
it does this when DecodeFrom() successfully reads and parses
the pointer blob and when the entirety of the blob's contents
have been read (i.e., there is no additional blob data to be
read).

This latter check was originally introduced in commit
e09e5e1 in PR git-lfs#271, when
the relevant code was in the Clean() method in the
pointer/clean.go file; it used the same 512 byte maximum
to determine if all the blob content had been read.  This
was aligned with the size of the byte array used in
DecodeFrom() in the pointer/pointer.go file.  The 512-byte
buffer created in DecodeFrom() was returned to Clean(),
which then checked its length to see if it had been fully
read or if there might still be additional data.

In commit f58db7f in
PR git-lfs#684 the size of the read buffer in DecodeFrom() was
changed from 512 bytes to the value of blobSizeCutoff, which
was 1024 (and remains so since).  However, the check in
Clean()'s copyToTemp() function was not changed at the same
time.  (Note that Clean() had been refactored and the check
was in copyToTemp(), where it remains.)

In commit 6f54232 in
PR git-lfs#1796 the DecodeFrom() method was changed to return an
io.Reader instead of a byte array, and copyToTemp() would
then read from that into a byte array using io.ReadAll().
That introduced a bug when handling large malformed pointers,
fixed in commit dcc0581 in
PR git-lfs#1852 by reading into a byte array in copyToTemp() with
blobSizeCutoff length.  However, the check for a resultant
data length of less than 512 bytes still remained in place.

In order to keep this blob size check in sync with the
allocated byte array in copyToTemp(), we therefore change
copyToTemp() so it checks if a pointer was successfully
read and the blob size is below blobSizeCutoff.  This
implies there is no more data to be read and we can
return a CleanPointerError (to signal a clean pointer was
found) and the byte array, which will then be written out,
leaving the blob's contents unchanged.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 11, 2021
When the "clean" filter processes a pre-existing LFS pointer
blob, the copyToTemp() function returns a CleanPointerError;
it does this when DecodeFrom() successfully reads and parses
the pointer blob and when the entirety of the blob's contents
have been read (i.e., there is no additional blob data to be
read).

This latter check was originally introduced in commit
e09e5e1 in PR git-lfs#271, when
the relevant code was in the Clean() method in the
pointer/clean.go file; it used the same 512 byte maximum
to determine if all the blob content had been read.  This
was aligned with the size of the byte array used in
DecodeFrom() in the pointer/pointer.go file.  The 512-byte
buffer created in DecodeFrom() was adjusted and returned to
Clean(), which then checked its length to see if it had been
populated to the 512-byte maximum, meaning there might still
be additional data to be read.

In commit f58db7f in
PR git-lfs#684 the size of the read buffer in DecodeFrom() was
changed from 512 bytes to the value of blobSizeCutoff, which
was 1024 (and remains so since).  However, the check in
Clean()'s copyToTemp() function was not changed at the same
time.  (Note that Clean() had been refactored and the check
was in copyToTemp(), where it remains.)

In commit 6f54232 in
PR git-lfs#1796 the DecodeFrom() method was changed to return an
io.Reader instead of a byte array, and copyToTemp() would
then read from that into a byte array using ioutil.ReadAll().
That introduced a bug when handling large malformed pointers,
fixed in commit dcc0581 in
PR git-lfs#1852 by reading into a byte array in copyToTemp() with
blobSizeCutoff length.  However, the check for a resultant
data length of less than 512 bytes still remained in place.

In order to keep this blob size check in sync with the
allocated byte array in copyToTemp(), we therefore change
copyToTemp() so it checks if a pointer was successfully
read and the blob size is below blobSizeCutoff.  This
implies there is no more data to be read and we can
return a CleanPointerError (to signal a clean pointer was
found) containing the byte array, which will then be written
out, leaving the blob's contents unchanged.
pcal43 pushed a commit to pcal43/git-lfs-hack that referenced this pull request Jul 22, 2021
When the "clean" filter processes a pre-existing LFS pointer
blob, the copyToTemp() function returns a CleanPointerError;
it does this when DecodeFrom() successfully reads and parses
the pointer blob and when the entirety of the blob's contents
have been read (i.e., there is no additional blob data to be
read).

This latter check was originally introduced in commit
e09e5e1 in PR git-lfs#271, when
the relevant code was in the Clean() method in the
pointer/clean.go file; it used the same 512 byte maximum
to determine if all the blob content had been read.  This
was aligned with the size of the byte array used in
DecodeFrom() in the pointer/pointer.go file.  The 512-byte
buffer created in DecodeFrom() was adjusted and returned to
Clean(), which then checked its length to see if it had been
populated to the 512-byte maximum, meaning there might still
be additional data to be read.

In commit f58db7f in
PR git-lfs#684 the size of the read buffer in DecodeFrom() was
changed from 512 bytes to the value of blobSizeCutoff, which
was 1024 (and remains so since).  However, the check in
Clean()'s copyToTemp() function was not changed at the same
time.  (Note that Clean() had been refactored and the check
was in copyToTemp(), where it remains.)

In commit 6f54232 in
PR git-lfs#1796 the DecodeFrom() method was changed to return an
io.Reader instead of a byte array, and copyToTemp() would
then read from that into a byte array using ioutil.ReadAll().
That introduced a bug when handling large malformed pointers,
fixed in commit dcc0581 in
PR git-lfs#1852 by reading into a byte array in copyToTemp() with
blobSizeCutoff length.  However, the check for a resultant
data length of less than 512 bytes still remained in place.

In order to keep this blob size check in sync with the
allocated byte array in copyToTemp(), we therefore change
copyToTemp() so it checks if a pointer was successfully
read and the blob size is below blobSizeCutoff.  This
implies there is no more data to be read and we can
return a CleanPointerError (to signal a clean pointer was
found) containing the byte array, which will then be written
out, leaving the blob's contents unchanged.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Jun 23, 2026
In a prior commit in this PR we introduced a new Go test helper
program named "lfstest-getlimit" which can return the value of
either the size of the read buffer used to decode Git LFS pointers
or the maximum length of a Git packet line.

We can now update a number of tests in our shell test suite to make
use of this helper utility.  Many of these tests previously relied on
hard-coded constants to create test data of various sizes to validate
the Git LFS client's ability to handle filter input data from Git
which fills or does not fill the client's pointer read buffer.

We rewrite one test in particular, the "clean pseudo pointer with
extra data" test in our "t/t-clean.sh" script, because its initial
version was written at a time when the size of the read buffer used
to decode Git LFS pointers was only 512 bytes, and the test has never
been appropriately revised.

The original version of this test was a Go test function named
TestCleanPointerWithWhitespaceAndExtra() that was added in commit
e09e5e1 of PR git-lfs#271.  The Go test
function was first rewritten as part of a shell test in commit
8b54aee of PR git-lfs#336, and then
converted into a separate shell test in commit
a251b2e of PR git-lfs#447.

Later, in commit f58db7f of PR git-lfs#684,
the size of the buffer used by the DecodeFrom() function in the "lfs"
package was changed from 512 bytes to the value specified by the
"blobSizeCutoff" constant.  At that point in time the constant was
already set to its current value of 1024 bytes.  However, the
"clean pseudo pointer with extra data" test was never updated to
reflect the larger size of the pointer read buffer.

We therefore now rewrite this test to retrieve the size of the
pointer read buffer using our new "lfstest-getlimit" utility, and
then create an invalid pointer larger than the size of the buffer.
Note that the test is intended in part to check that the client
ignores the fact that the initial portion of the input data appears
to be a valid Git LFS pointer.  The exact content of this initial
portion is not significant, however, so we change the value of the
"size" field in the invalid pointer from 1024 to 9999, which more
clearly indicates that this value is arbitrary and not related
to the size of the client's read buffer.

What is important for the soundness of the test, though, is that the
total length of the invalid pointer data exceeds the buffer's size.
To align with the original design of the test, we insert a large
number of linefeed characters after the initial portion of the test
data, which requires us to work around the fact that the shell will
strip trailing whitespace from a command substitution.  To avoid our
linefeed characters being removed from the value we assign to the
"fill" shell variable, we append the string "EOF", and then remove
this suffix when interpolating the variable's value into the final
version of the test data that we pass to the "git lfs clean" command.

To maintain consistency between our tests, we also update the
preceding "clean pseudo pointer" test in the "t/t-clean.sh" script to
change the arbitrary value of the "size" field in its invalid pointer
data from 1024 to 9999.  This test's invalid pointer data is not
intended to exceed the size of the client's read buffer, so we do
not need to invoke our new "lfstest-getlimit" helper utility.  The
data only needs to begin with an apparently valid set of pointer fields,
but as with the following test, the exact value of the "size" field is
not significant, which is more clearly indicated by the value 9999.

Both of these tests previously used hard-coded SHA-256 hash values
to check the output of the "git lfs clean" command, which should
simply process the invalid pointer data as a regular file and not
a Git LFS pointer.  Since we have changed the input data in both
tests, we need to recalculate the expected SHA-256 hashes.  While
we could continue to use hard-coded hash values, we instead make use
of our test helper functions to now calculate these hash values
dynamically.

We then update a number of other tests in several scripts to make
use of our new "lfstest-getlimit" helper utility.  All of these
tests previously used hard-coded values to create data of a specific
length in order to demonstrate that the Git LFS client does not
exhibit undesired behaviour when its input data fills or does not
fill a given internal buffer.

Note, though, that in the "malformed pointers" test we still have
one instance where we create a file of a specific size using a
hard-coded constant value.  In this instance, the test checks that
the Git LFS client can process invalid pointer data from Git which
exceeds the default capacity of a pipe, which is normally 64 kB,
at least on Linux and macOS.

We should be able to dynamically determine the capacity of a pipe
on Linux using the fcntl(2) system call and the F_GETPIPE_SZ operation,
and on Windows using the GetNamedPipeInfo() system call and the
"lpInBufferSize" and "lpOutBufferSize" parameters:

  https://man7.org/linux/man-pages/man2/F_GETPIPE_SZ.2const.html
  https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-getnamedpipeinfo#parameters

However, on macOS we would apparently have to experimentally feed
data into a pipe to try to determine the pipe's capacity.  This is
beyond the scope of the current PR, though, so for the present
time we leave this one instance of a hard-coded buffer size in
our shell tests.  We add a comment which explains the intent of this
check, however, as a reminder to revisit this issue in the future.

To help clarify the behaviour of the many tests where we simply need
to generate a file of a specific length, we now adopt the use of the
head(1) command to read a specific number of zero bytes from the
"/dev/zero" pseudo-device instead of using the dd(1) command as we
have done previously.  The result is the same in all cases, but the
"dd" command requires several somewhat obscure options, while the
"head" command only requires a single byte-count argument.

In addition to these changes to the tests, we also add or update
the comments in the tests.  In each case, we try to more fully
document the purpose of the test, with links to the original issues
and PRs for which the test was developed.

Finally, we revise the names of two of the tests in our
"t/t-filter-process.sh" script.  We rename the "filter process: add a
file with 1024 bytes" test to "filter process: non-pointer file of
maximum pointer size", since the size of the file created by the test
is now variable rather than fixed, and the intent of the test is
to check that the Git LFS client properly handles filter input which
happens to be exactly the same size as that of the pointer read
buffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants