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 padding calculation, closes #45 #46

Merged
merged 29 commits into from
Mar 23, 2021
Merged

Conversation

peternewman
Copy link
Contributor

@peternewman peternewman commented Nov 25, 2020

Fixes #45

Untested, but maths checked externally

Could probably do with some tests to catch such issues in future.

@peternewman peternewman marked this pull request as draft March 19, 2021 02:17
osc/osc.go Outdated Show resolved Hide resolved
osc/osc_test.go Outdated Show resolved Hide resolved
osc/osc.go Outdated Show resolved Hide resolved
Copy link
Contributor

@chabad360 chabad360 left a comment

Choose a reason for hiding this comment

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

See the comments regarding the string delimiter

osc/osc_test.go Outdated Show resolved Hide resolved
@peternewman peternewman changed the title Fix padding calculation, hopefully fixes #45 Fix padding calculation, closes #45 Mar 22, 2021
Copy link
Contributor

@chabad360 chabad360 left a comment

Choose a reason for hiding this comment

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

LGTM.

@chabad360
Copy link
Contributor

chabad360 commented Mar 22, 2021

You should probably update the PR text to at least say fixes #45, this way it'll be automatically closed. Also, make sure to mark it ready for review.

Copy link
Contributor

@chabad360 chabad360 left a comment

Choose a reason for hiding this comment

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

Oops, forgot one more thing: writePaddedString() needs to be modified as well, otherwise we still have this issue.

@peternewman
Copy link
Contributor Author

You should probably update the PR text to at least say fixes #45, this way it'll be automatically closed. Also, make sure to mark it ready for review.

I thought it worked in the title too, but added to both to be sure.

@peternewman peternewman marked this pull request as ready for review March 22, 2021 16:28
@peternewman
Copy link
Contributor Author

Oops, forgot one more thing: writePaddedString() needs to be modified as well, otherwise we still have this issue.

I don't see where @chabad360 . It uses the count from writeString which presumably already includes the null terminator. Or do you mean we need to ensure one is added?

@chabad360
Copy link
Contributor

chabad360 commented Mar 22, 2021

We need to ensure one is added.

I would just add

buf.WriteByte(0)
n += 1

right after buf.WriteString() (worked for me).

@peternewman
Copy link
Contributor Author

We need to ensure one is added.

I would just add

buf.WriteByte(0)
n += 1

right after buf.WriteString() (worked for me).

Won't that get a double one if the string already has one (or is that impossible/guaranteed in Go)? Consider:
't', 'e', 's', '\0'
You'd end up sending:
't', 'e', 's', 0, 0, 0, 0, 0

@chabad360
Copy link
Contributor

Unless you specifically craft a string to include a null byte string([]byte{0}), a string shouldn't contain one. However, because it's not simple to add a null byte efficiently (nor is it idiomatic), it's safer to assume it's not there. Additionally, all the tests I ran (and some analysis) showed that the library doesn't insert any null bytes.

osc/osc.go Outdated Show resolved Hide resolved
osc/osc_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@chabad360 chabad360 left a comment

Choose a reason for hiding this comment

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

Alright, LGTM. @hypebeast?

Copy link
Owner

@hypebeast hypebeast left a comment

Choose a reason for hiding this comment

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

Very nice. This PR looks good to me.

Thanks a lot for it. As soon as the build succeeds I'll merge it.

osc/osc.go Outdated Show resolved Hide resolved
osc/osc.go Outdated Show resolved Hide resolved
@peternewman
Copy link
Contributor Author

Very nice. This PR looks good to me.

Thanks @hypebeast . It seems to works for all the test cases @chabad360 came up with and a few edge cases I conjured up too.

Thanks a lot for it.

No worries, not quite the easy fix I first thought, but hopefully should make things better and more standardised all round.

@peternewman
Copy link
Contributor Author

This now passes aside from https://travis-ci.org/github/hypebeast/go-osc/jobs/764014122#L275-L279 which is also present in master @hypebeast .

Looks like this could fix it, but a bit outside my experience:
ipfs/kubo#2043

@chabad360
Copy link
Contributor

I would say that issue is probably outside the scope of this PR.

@hypebeast
Copy link
Owner

Yes, this is outside of this PR. Let me see if I can fix it ;)

Thanks again for your work @peternewman and @chabad360

@hypebeast hypebeast merged commit 9e122b7 into hypebeast:master Mar 23, 2021
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.

Invalid blobs generated
3 participants