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

[SR-12553] A manifest that emits stdout data can result in failure with the one-word message "malformed" #4565

Closed
abertelrud opened this issue Apr 8, 2020 · 1 comment
Assignees
Labels

Comments

@abertelrud
Copy link
Contributor

Previous ID SR-12553
Radar rdar://61409079
Original Reporter @abertelrud
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee @abertelrud
Priority Medium

md5: 6efdf37ed86878a69d530a7eb03b1734

Issue Description:

If a package manifest emits output to file description 1 (stdout) – using print(), for example) – then the parsing of the manifest can fail with the single-word error message "malformed".

This seems to be the localizable description of a JSON parsing error that's thrown when the input is malformed. It happens if the amount of standard output overflows the stdio buffer, or if the output is unbuffered for other reasons.

This example manifest illustrates the problem:

import PackageDescription
print(String(repeating: "Hello manifest... ", count: 65536))
let package = Package(name: "PackageWithChattyManifest")

This is seen both in SwiftPM 5.3 and in the master branch as of at least d196d9d.

The reason this works sometimes is that if the amount of emitted text is small enough, the buffer is never flushed before libPackageDescription emits the resulting JSON to stdout (without going through buffered I/O, so it bypasses the buffered data and never flushes the buffer).

The compiled package manifest is passed a -fileno parameter, but it is currently always passed 1, which is stdout. The solution here is probably to open a new file descriptor for the JSON data and pass that to the compiled package manifest.

In addition to this, we should probable improve the error message that's shown if malformed JSON data does make it to SwiftPM itself.

@abertelrud
Copy link
Contributor Author

Fixed in ab8d72c

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant