Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/native/corehost/bundle/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "pal.h"
#include "utils.h"
#include <cinttypes>
#include <cerrno>

#ifdef __sun
#include <alloca.h>
Expand Down Expand Up @@ -156,10 +157,20 @@ void extractor_t::extract(const file_entry_t &entry, reader_t &reader)
}

int produced = bufSize - zStream.availOut;
if (fwrite(buf, 1, produced, file) != (size_t)produced)
size_t written = fwrite(buf, 1, produced, file);
if (written != (size_t)produced)
{
CompressionNative_InflateEnd(&zStream);
trace::error(_X("I/O failure when writing decompressed file."));
if (ferror(file))
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like ferror sets errno. But it looks like fwrite almost always does. Let's just print errno in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to always print errno without checking ferror. Commit: 5b4f0d2

{
int err = errno;
trace::error(_X("I/O error detected. errno: %d, %s"), err, pal::strerror(err).c_str());
}
else
{
trace::error(_X("Short write detected. Expected: %d bytes, Written: %zu bytes"), produced, written);
}
throw StatusCode::BundleExtractionIOError;
}

Expand All @@ -181,10 +192,26 @@ void extractor_t::extract(const file_entry_t &entry, reader_t &reader)
{
trace::error(_X("Failure extracting contents of the application bundle. Expected size:%" PRId64 " Actual size:%zu"), size, extracted_size);
trace::error(_X("I/O failure when writing extracted files."));
if (ferror(file))
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to always print errno without checking ferror. Commit: 5b4f0d2

{
int err = errno;
trace::error(_X("I/O error detected. errno: %d, %s"), err, pal::strerror(err).c_str());
}
else
{
trace::error(_X("Short write detected. Expected: %zu bytes, Written: %zu bytes"), cast_size, extracted_size);
}
fclose(file);
throw StatusCode::BundleExtractionIOError;
}

fclose(file);
if (fclose(file) != 0)
Copy link
Member

Choose a reason for hiding this comment

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

Let's ignore fclose failures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed fclose error checking. Commit: 5b4f0d2

{
int err = errno;
trace::error(_X("Failure extracting contents of the application bundle."));
trace::error(_X("Failed to close file after extraction. errno: %d, %s"), err, pal::strerror(err).c_str());
throw StatusCode::BundleExtractionIOError;
}
}

void extractor_t::begin()
Expand Down
Loading