[attribute] When updating attribution, zero out the anchor/sentinel prior to placing the new value in

This ensures that attribution codes that are shorter than the anchor/sentinel will not be mangled.
This commit is contained in:
Ben Hearsum 2023-08-21 21:30:32 -04:00
Родитель b7e8a81a53
Коммит 0950317f39
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: A4B76C1E8BED5BFD
2 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -274,6 +274,12 @@ int updateAttribution(AbstractFile* abstractIn, AbstractFile* abstractOut, const
printf("anchorOffset: 0x%llx\n", anchorOffset); printf("anchorOffset: 0x%llx\n", anchorOffset);
ASSERT(rawAnchor + dataLen <= rawBuffer + attributionResource->rawLength, "data too long!"); ASSERT(rawAnchor + dataLen <= rawBuffer + attributionResource->rawLength, "data too long!");
// Zero out the anchor area, in case the data is shorter than the anchor
// Note that we're taking the strlen of `rawAnchor` and not the `anchor`
// passed in. This ensures that the entire anchor is zero'ed, even if only
// a prefix of it was provided.
memset((void *)rawAnchor, 0, strlen(rawAnchor));
// Copy the new data into the same spot the anchor was in
memcpy((void *)rawAnchor, data, dataLen); memcpy((void *)rawAnchor, data, dataLen);
// Write the new block. // Write the new block.

Просмотреть файл

@ -0,0 +1,33 @@
Make sure we have a fresh build:
$ export BUILDDIR=$TESTDIR/../build
$ cd $BUILDDIR
$ make 2> /dev/null >/dev/null
$ cd $CRAMTMP
Prepare content and the attribution code:
$ mkdir stagedir
$ echo "content-a" >> stagedir/a
$ sentinel="__MOZILLA__attribution-code"
$ attribution_code="short"
Create the filesystem with the sentinel value in the attribute:
$ mkdir output
$ cp $TESTDIR/empty.hfs output/short.hfs
$ $BUILDDIR/hfs/hfsplus output/short.hfs add stagedir/a a
$ $BUILDDIR/hfs/hfsplus output/short.hfs setattr a attr-key "$sentinel"
Build a DMG:
$ $BUILDDIR/dmg/dmg build output/short.hfs output/short.dmg "$sentinel" >/dev/null
Now attribute:
$ $BUILDDIR/dmg/dmg attribute output/short.dmg output/short-attributed.dmg "__MOZILLA__" "$attribution_code" >/dev/null
Extract the HFS from the attributed DMG, and check to see if the code is correct:
$ $BUILDDIR/dmg/dmg extract output/short-attributed.dmg output/short-attributed.hfs >/dev/null
$ $BUILDDIR/hfs/hfsplus output/short-attributed.hfs getattr a attr-key | tr -d '\0'
short (no-eol)