Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong file header used when opening two file channels #168

Closed
infeo opened this issue Apr 11, 2023 · 0 comments
Closed

Wrong file header used when opening two file channels #168

infeo opened this issue Apr 11, 2023 · 0 comments
Assignees
Labels
Milestone

Comments

@infeo
Copy link
Member

infeo commented Apr 11, 2023

The file header should be shared between all related OpenFileobjects (ChunkSaver, ChunkLoader and CleartextFileChannel via the file header holder to ensure consistency. But only the Chunk* classes share the header. The CleartextFileChannel, once created, uses always the same header.

This causes data corruption, if during the lifetime of the channel the file header changes. (e.g., by opening a second file channel and closing it again).

Example test code:

		@Test
		@DisplayName("Specific pattern")
		public void testPattern() throws IOException {

			try(var ch = FileChannel.open(file,READ, WRITE, CREATE_NEW)) {
				try(var ch2 = FileChannel.open(file,WRITE)) {
				}
				ch.write(ByteBuffer.wrap(new byte[]{0x1}), 0);
			}
			try(var ch = FileChannel.open(file,READ)) {
				ch.read(ByteBuffer.allocate(10),0);
			}
		}
@infeo infeo added the bug label Apr 11, 2023
@infeo infeo added this to the 2.6.4 milestone Apr 11, 2023
@infeo infeo self-assigned this Apr 11, 2023
@infeo infeo closed this as completed in f426f74 Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant