Skip to content

Fix decoding NSData from an NSCoder #1447

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

Merged

Conversation

gmilos
Copy link
Contributor

@gmilos gmilos commented Feb 21, 2018

The new test case shows how NSData decoding could fail. Fix included.

@gmilos gmilos requested review from phausler and spevans February 21, 2018 18:04
@millenomi
Copy link
Contributor

@swift-ci please test

let data = NSData(bytes: bytes, length: bytes.count)

let archiver = NSKeyedArchiver()
let key = "data"
Copy link
Contributor

Choose a reason for hiding this comment

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

key is never used.

data.encode(with: archiver)
let encodedData = archiver.encodedData

let unarchiver = NSKeyedUnarchiver(forReadingWithData: encodedData)
Copy link
Contributor

Choose a reason for hiding this comment

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

According to https://developer.apple.com/documentation/foundation/nskeyedunarchiver/1410862-init the method is init(forReadingWith data: Data) so needs a small adjustment.

@gmilos gmilos force-pushed the rdar-37462656-data-nskeyedunarchiver-fix branch from 5143e01 to a7e594e Compare February 22, 2018 11:51
@gmilos
Copy link
Contributor Author

gmilos commented Feb 22, 2018

@swift-ci please test

@gmilos
Copy link
Contributor Author

gmilos commented Feb 22, 2018

@spevans thanks for the comments. Fixed both. Botched rebase, apologies.

@spevans
Copy link
Contributor

spevans commented Feb 22, 2018

@swift-ci please test

2 similar comments
@spevans
Copy link
Contributor

spevans commented Feb 22, 2018

@swift-ci please test

@spevans
Copy link
Contributor

spevans commented Feb 23, 2018

@swift-ci please test

@kevints
Copy link
Contributor

kevints commented Oct 9, 2018

@gmilos looks like this one didn't go in either. Needs a rebase now

@millenomi
Copy link
Contributor

Is this relevant still? as? Data should work for both NSData and Data values now.

@millenomi
Copy link
Contributor

@swift-ci please test

@millenomi
Copy link
Contributor

I’m closing this for now as no longer relevant. Please ping me if you feel this is done in error.

@millenomi millenomi closed this Oct 16, 2018
@kevints
Copy link
Contributor

kevints commented Oct 16, 2018

@millenomi @gmilos is out this week but i think this patch is still relevant - if not the implementation the test case should still be merged

@millenomi millenomi reopened this Oct 16, 2018
@millenomi
Copy link
Contributor

Reopened.

@spevans
Copy link
Contributor

spevans commented Oct 16, 2018

I just ran the test against master and it worked OK so its probably worth adding the just the test to catch any later regressions.

Since `as? Data` now works from a NSData object (but requires an extra bridging call), keep the status quo.
@millenomi
Copy link
Contributor

@swift-ci please test and merge

@millenomi
Copy link
Contributor

@swift-ci please test and merge

1 similar comment
@millenomi
Copy link
Contributor

@swift-ci please test and merge

@swift-ci swift-ci merged commit 9bd3de2 into swiftlang:master Oct 16, 2018
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.

5 participants