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

Make sure Stream.start_position is relative to the whole file. #59

Merged
merged 1 commit into from May 9, 2019

Conversation

jothan
Copy link
Contributor

@jothan jothan commented May 8, 2019

I noticed this while writing the nom parser.

This is to make sure this code works in reader.rs:

if let Some(start) = stream.start_position {
    let end = start + length as usize;
    stream.set_content(self.buffer[start..end].to_vec());
}

@J-F-Liu
Copy link
Owner

J-F-Liu commented May 9, 2019

Will this self.start_position = self.start_position.and_then(|sp| sp.checked_add(file_offset)) change self.start_position? Why add file_offset to it?

@jothan
Copy link
Contributor Author

jothan commented May 9, 2019

Because start_position is then used to index into self.buffer in Reader::read. It is used relative to the start of the file, it should therefore be relative to the start of the file.

Yes, it changes self.start_position.

@J-F-Liu
Copy link
Owner

J-F-Liu commented May 9, 2019

I see. The initial value of start_position is relative to stream object's offset, this is a bug introduced when upgrade to pom 3.0.

@J-F-Liu J-F-Liu merged commit cdfa0c1 into J-F-Liu:master May 9, 2019
@J-F-Liu
Copy link
Owner

J-F-Liu commented May 9, 2019

A better way is change

parser::indirect_object(self)
			.parse(&self.buffer[offset..])

to

parser::indirect_object(self)
			.parse_at(&self.buffer, offset)

@jothan jothan deleted the offset_fix branch May 9, 2019 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants