[ostree] corrupt-repo-ref.js: more aggressive file corruption
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] corrupt-repo-ref.js: more aggressive file corruption
- Date: Wed, 22 Oct 2014 18:13:56 +0000 (UTC)
commit 49de180191334ba1743d6d217590db3ec66309f6
Author: Giuseppe Scrivano <gscrivan redhat com>
Date: Wed Oct 22 19:52:12 2014 +0200
corrupt-repo-ref.js: more aggressive file corruption
changing only a byte may not generate a corrupted file, so play very
safe and change 10 bytes.
Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
tests/corrupt-repo-ref.js | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/tests/corrupt-repo-ref.js b/tests/corrupt-repo-ref.js
index b1a797d..c5f2806 100644
--- a/tests/corrupt-repo-ref.js
+++ b/tests/corrupt-repo-ref.js
@@ -72,17 +72,26 @@ let loosePath = repo.get_path().resolve_relative_path('objects/' + objectToCorru
let iostream = loosePath.open_readwrite(null);
let info = iostream.query_info('standard::size', null);
let size = info.get_size();
-let byteOffsetToCorrupt = GLib.random_int_range(0, size);
-iostream.seek(byteOffsetToCorrupt, GLib.SeekType.SET, null);
let datain = Gio.DataInputStream.new(iostream.get_input_stream());
let dataout = Gio.DataOutputStream.new(iostream.get_output_stream());
-let inbyte = datain.read_byte(null);
-let outbyte = (inbyte + 1) % 255;
-dataout.put_byte(outbyte, null);
+let bytesToChange = 10;
+let status = "";
+var bytesChanged = {}
+for (i = 0; i < bytesToChange; i++) {
+ let byteOffsetToCorrupt;
+ do {
+ byteOffsetToCorrupt = GLib.random_int_range(0, size);
+ } while (byteOffsetToCorrupt in bytesChanged);
+ iostream.seek(byteOffsetToCorrupt, GLib.SeekType.SET, null);
+ let inbyte = datain.read_byte(null);
+ let outbyte = (inbyte + 1) % 255;
+ dataout.put_byte(outbyte, null);
+ bytesChanged[byteOffsetToCorrupt] = byteOffsetToCorrupt;
+ status += "Changed byte offset " + byteOffsetToCorrupt + " from " + inbyte + " to " + outbyte + "\n";
+}
dataout.flush(null);
iostream.close(null);
-let status = "Changed byte offset " + byteOffsetToCorrupt + " from " + inbyte + " to " + outbyte;
-print(status);
+print(status);
let successFile = Gio.File.new_for_path('corrupted-status.txt');
successFile.replace_contents(status, null, false, 0, null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]