
gzip圧縮ファイル(約3Kb)がありますが、サイズが正確に4000であることを望みます。
これを達成するために末尾のパディング0を追加するのは安全ですか? (セキュリティとは、gzipで圧縮されたファイルの内容をエラーなく圧縮できることを意味します。)
dd if=/dev/zero of=/myfile bs=1 count=4000
dd if=/gzipfile.gz of=/myfile
これが安全でない場合、代替案はありますか?
答え1
マニュアルページから:
CAVEATS When writing compressed data to a tape, it is generally necessary to pad the output with zeroes up to a block boundary. When the data is read and the whole block is passed to gun‐ zip for decompression, gunzip detects that there is extra trailing garbage after the compressed data and emits a warning by default. You have to use the --quiet option to suppress the warning.
だからあなたは安全に見えますね。
conv=notrunc
2番目の呼び出しに合格する必要があるため、コードは機能しません
dd
。
または、次のことができます。
dd bs=4000 seek=1 count=0 of=file.gz
または
truncate -s 4000 file.gz
サイズを4000バイトにしてください(実際にゼロを書く必要なしに稀に作成してください)。