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

Fix panic due to range out of bounds in txt record parsing #159

Merged
merged 3 commits into from
Dec 24, 2023

Conversation

Raphiiko
Copy link
Contributor

I noticed the following panic in my crash reporting earlier:

range end index 303 out of range for slice of length 288 (C:\...\src\service_info.rs:645:25)

I'm not entirely sure if this would be the correct solution, but I've made an attempt.

Copy link
Owner

@keepsimple1 keepsimple1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! Fix looks nice, only a minor comment inline.

let kv_bytes = &txt[offset..offset + length];
let offset_end = offset + length;
if offset_end > txt.len() {
break; // Would be out of range, skipping this property.
Copy link
Owner

@keepsimple1 keepsimple1 Dec 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense! Could you also add a log of offset_end and txt.len() when this happens? I would say error!() level. And if error!() doesn't work for you, debug!() level is also fine.

Can you also add a unit test in this file inside mod tests for this negative case? A simple test input would be fine.

ps. A nitty: it is not only "skipping this property", it's actually "skipping the rest of TXT" .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I've give given it a go!

Copy link
Owner

@keepsimple1 keepsimple1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks!

@keepsimple1 keepsimple1 merged commit 7e27e28 into keepsimple1:main Dec 24, 2023
3 checks passed
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.

2 participants