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

Global namespace pollution; stringRefs ? #55

Open
BurtHarris opened this issue Nov 17, 2022 · 3 comments
Open

Global namespace pollution; stringRefs ? #55

BurtHarris opened this issue Nov 17, 2022 · 3 comments

Comments

@BurtHarris
Copy link
Contributor

BurtHarris commented Nov 17, 2022

Reading decode.js it looks like there is an undeclared variable stringRefs. Am I correct that the implementation of tags 25 and 256 is incomplete?

Perhaps the following should be commented out to avoid treating stringRefs as a property of the global object.

currentExtensions[25] = (id) => {
	return stringRefs[id]
}
currentExtensions[256] = (read) => {
	stringRefs = []
	try {
		return read()
	} finally {
		stringRefs = null
	}
}
currentExtensions[256].handlesRead = true

I'll submit a PR including that if you agree.

@BurtHarris BurtHarris changed the title Global namespace pollution in code for string reference Tags Global namespace pollution; stringRefs ? Nov 17, 2022
@kriszyp
Copy link
Owner

kriszyp commented Nov 17, 2022

Yes, you are correct, that is a global and should have been scoped to the module. A PR is welcome, thank you!

@BurtHarris
Copy link
Contributor Author

BurtHarris commented Dec 3, 2022

Digging in, I see that stringRefs decode is not complete. I looked into completing it, but interactions with bundled strings would make the code ugly. And test cases exercising the logic would be hard to come by...

So actually my suggestion will be to remove the stringRef extension table entries.

BurtHarris added a commit to BurtHarris/cbor-x that referenced this issue Dec 3, 2022
Comment out decode tag 25 & 256.    Making it work would further complicate read and bundled strings.

Fixes: Global namespace pollution; `stringRefs` ?  kriszyp#55
@here-abarany
Copy link

And test cases exercising the logic would be hard to come by...

If you want to create examples, Python's cbor2 module supports stringrefs. The main thing to test for is the correlation between the string length and index size when determining whether to add a string to the reference table. (see also the stringref reference, which has some examples as well)

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

No branches or pull requests

3 participants