[gparted] Add test that PipeCapture can read NUL byte in middle of UTF-8 char (#777973)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Add test that PipeCapture can read NUL byte in middle of UTF-8 char (#777973)
- Date: Sat, 3 Jun 2017 15:43:12 +0000 (UTC)
commit 6b82616d2e5dfddea8b73cc65d64bfc7e08d8388
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Thu May 25 11:38:43 2017 +0100
Add test that PipeCapture can read NUL byte in middle of UTF-8 char (#777973)
Test that binary data that happens to be the start of a multi-byte UTF-8
character but then contains a NUL byte is successfully read. The test
currently detects failure thus:
$ ./test_PipeCapture
...
[ RUN ] PipeCaptureTest.ReadNULByteInMiddleOfMultiByteUTF8Character
test_PipeCapture.cc:346: Failure
Expected: expectedstr
Of length: 7
To be equal to: capturedstr.raw()
Of length: 0
With first binary difference:
< 0x00000000 "._45678" 00 5F 34 35 36 37 38
--
> 0x00000000 ""
[ FAILED ] PipeCaptureTest.ReadNULByteInMiddleOfMultiByteUTF8Character (0 ms)
...
Bug 777973 - Segmentation fault on bad disk
tests/test_PipeCapture.cc | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_PipeCapture.cc b/tests/test_PipeCapture.cc
index a45804b..608d171 100644
--- a/tests/test_PipeCapture.cc
+++ b/tests/test_PipeCapture.cc
@@ -337,6 +337,23 @@ TEST_F( PipeCaptureTest, ReadEmbeddedNULCharacter )
EXPECT_TRUE( eof_signalled );
}
+TEST_F( PipeCaptureTest, ReadNULByteInMiddleOfMultiByteUTF8Character )
+{
+ // Test NUL byte in the middle of reading a multi-byte UTF-8 character.
+ const char * buf = "\xC0\x00_45678";
+ inputstr = std::string( buf, 8 );
+ PipeCapture pc( pipefds[ReaderFD], capturedstr );
+ pc.signal_eof.connect( sigc::mem_fun( *this, &PipeCaptureTest::eof_callback ) );
+ pc.connect_signal();
+ run_writer_thread();
+ // Initial \xC0 byte is part of an incomplete UTF-8 characters so will be skipped
+ // by PipeCapture.
+ buf = "\x00_45678";
+ expectedstr = std::string( buf, 7 );
+ EXPECT_BINARYSTRINGEQ( expectedstr, capturedstr.raw() );
+ EXPECT_TRUE( eof_signalled );
+}
+
} // namespace GParted
// Custom Google Test main() which also initialises the Glib threading system for
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]