tools/delta: check pwrite result in bmpatch

Detect short writes and errors instead of advancing the output offset
as if all bytes were written, which could silently corrupt the image.
pull/814/head
Daniele Lacamera 2026-07-02 17:01:28 +02:00
parent d977baa60e
commit 103eec95fe
1 changed files with 9 additions and 1 deletions

View File

@ -149,7 +149,15 @@ int main(int argc, char *argv[])
if (r < 0)
exit(5);
if (r > 0) {
pwrite(fd1, dest, r, len3);
int off = 0;
while (off < r) {
ssize_t wr = pwrite(fd1, dest + off, r - off, len3 + off);
if (wr <= 0) {
perror("pwrite");
exit(5);
}
off += (int)wr;
}
len3 += r;
}
} while (r > 0);