]> git.ipfire.org Git - thirdparty/git.git/commit - dir.c
dir: support platforms that require aligned reads
authorRené Scharfe <l.s.r@web.de>
Sun, 16 Jul 2017 12:17:37 +0000 (14:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Jul 2017 21:56:16 +0000 (14:56 -0700)
commit268ba20110f9e6aca3a7bf8b256f7a8fbfd2dab9
tree23c369ba892f84cbdffdbc7d09e12fa20dc82e34
parent95d67879735cfecfdd85f89e59d993c5b4de8835
dir: support platforms that require aligned reads

The untracked cache is stored on disk by concatenating its memory
structures without any padding.  Consequently some of the structs are
not aligned at a particular boundary when the whole extension is read
back in one go.  That's only OK on platforms without strict alignment
requirements, or for byte-aligned data like strings or hash values.

Decode struct ondisk_untracked_cache carefully from the extension
blob by using explicit pointer arithmetic with offsets, avoiding
alignment issues.  Use char pointers for passing stat_data objects to
stat_data_from_disk(), and use memcpy(3) in that function to  get the
contents into a properly aligned struct, then perform the byte-order
adjustment in place there.

Found with Clang's UBSan.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c