+// Data with a truncated marker should first give the first bytes, then failure
+// on next read since the stream EOFs.
+void test_broken_marker()
+{
+ uint8_t bytes[] = { 0x01, 0x02, 0x03, 0x04, 0xff };
+ uint8_t expected_bytes[] = { 0x01, 0x02, 0x03, 0x04 };
+
+ struct custom_read_userdata ud;
+ ud.bytes = bytes;
+ ud.bytes_left = sizeof(bytes);
+
+ struct byte_source source;
+ init_byte_source(&source, custom_read, &ud);
+
+ uint8_t buf[4096];
+ ssize_t ret;
+
+ ret = byte_source_input_func(&source, buf, 4096);
+ assert(ret == sizeof(expected_bytes));
+ assert(memcmp(buf, expected_bytes, sizeof(expected_bytes)) == 0);
+
+ ret = byte_source_input_func(&source, buf, 4096);
+ assert(ret == -1);
+}
+