0

Prevent unsafe narrowing: base/files

Bug: 1292951
Change-Id: Ie7489503b41003ec3f4ec97991b39e4d82009c58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3691384
Reviewed-by: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1011590}
This commit is contained in:
Peter Kasting
2022-06-07 18:55:25 +00:00
committed by Chromium LUCI CQ
parent 5bc2e37231
commit 2d40b0f239
39 changed files with 131 additions and 100 deletions

@ -95,7 +95,7 @@ class CreateOrOpenHelper : public FileHelper {
CreateOrOpenHelper(const CreateOrOpenHelper&) = delete;
CreateOrOpenHelper& operator=(const CreateOrOpenHelper&) = delete;
void RunWork(const FilePath& file_path, int file_flags) {
void RunWork(const FilePath& file_path, uint32_t file_flags) {
file_.Initialize(file_path, file_flags);
error_ = file_.IsValid() ? File::FILE_OK : file_.error_details();
}
@ -175,7 +175,7 @@ class ReadHelper : public FileHelper {
public:
ReadHelper(FileProxy* proxy, File file, int bytes_to_read)
: FileHelper(proxy, std::move(file)),
buffer_(new char[bytes_to_read]),
buffer_(new char[static_cast<size_t>(bytes_to_read)]),
bytes_to_read_(bytes_to_read) {}
ReadHelper(const ReadHelper&) = delete;
ReadHelper& operator=(const ReadHelper&) = delete;
@ -204,9 +204,9 @@ class WriteHelper : public FileHelper {
const char* buffer,
int bytes_to_write)
: FileHelper(proxy, std::move(file)),
buffer_(new char[bytes_to_write]),
buffer_(new char[static_cast<size_t>(bytes_to_write)]),
bytes_to_write_(bytes_to_write) {
memcpy(buffer_.get(), buffer, bytes_to_write);
memcpy(buffer_.get(), buffer, static_cast<size_t>(bytes_to_write));
}
WriteHelper(const WriteHelper&) = delete;
WriteHelper& operator=(const WriteHelper&) = delete;
@ -239,7 +239,7 @@ FileProxy::~FileProxy() {
}
bool FileProxy::CreateOrOpen(const FilePath& file_path,
int file_flags,
uint32_t file_flags,
StatusCallback callback) {
DCHECK(!file_.IsValid());
CreateOrOpenHelper* helper = new CreateOrOpenHelper(this, File());

@ -59,7 +59,7 @@ class BASE_EXPORT FileProxy : public SupportsWeakPtr<FileProxy> {
//
// This returns false if task posting to |task_runner| has failed.
bool CreateOrOpen(const FilePath& file_path,
int file_flags,
uint32_t file_flags,
StatusCallback callback);
// Creates a temporary file for writing. The path and an open file are

@ -101,7 +101,8 @@ bool CopyFileContents(File& infile, File& outfile) {
std::vector<char> buffer(kBufferSize);
for (;;) {
int bytes_read = infile.ReadAtCurrentPos(buffer.data(), buffer.size());
int bytes_read =
infile.ReadAtCurrentPos(buffer.data(), static_cast<int>(buffer.size()));
if (bytes_read < 0) {
return false;
}
@ -112,7 +113,8 @@ bool CopyFileContents(File& infile, File& outfile) {
int bytes_written_per_read = 0;
do {
int bytes_written_partial = outfile.WriteAtCurrentPos(
&buffer[bytes_written_per_read], bytes_read - bytes_written_per_read);
&buffer[static_cast<size_t>(bytes_written_per_read)],
bytes_read - bytes_written_per_read);
if (bytes_written_partial < 0) {
return false;
}
@ -228,8 +230,8 @@ bool ReadStreamToStringWithMaxSize(FILE* stream,
// Many files have incorrect size (proc files etc). Hence, the file is read
// sequentially as opposed to a one-shot read, using file size as a hint for
// chunk size if available.
constexpr int64_t kDefaultChunkSize = 1 << 16;
int64_t chunk_size = kDefaultChunkSize - 1;
constexpr size_t kDefaultChunkSize = 1 << 16;
size_t chunk_size = kDefaultChunkSize - 1;
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
#if BUILDFLAG(IS_WIN)
BY_HANDLE_FILE_INFORMATION file_info = {};
@ -237,25 +239,25 @@ bool ReadStreamToStringWithMaxSize(FILE* stream,
reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(stream))),
&file_info)) {
LARGE_INTEGER size;
size.HighPart = file_info.nFileSizeHigh;
size.HighPart = static_cast<LONG>(file_info.nFileSizeHigh);
size.LowPart = file_info.nFileSizeLow;
if (size.QuadPart > 0)
chunk_size = size.QuadPart;
chunk_size = static_cast<size_t>(size.QuadPart);
}
#else // BUILDFLAG(IS_WIN)
// In cases where the reported file size is 0, use a smaller chunk size to
// minimize memory allocated and cost of string::resize() in case the read
// size is small (i.e. proc files). If the file is larger than this, the read
// loop will reset |chunk_size| to kDefaultChunkSize.
constexpr int64_t kSmallChunkSize = 4096;
constexpr size_t kSmallChunkSize = 4096;
chunk_size = kSmallChunkSize - 1;
stat_wrapper_t file_info = {};
if (!File::Fstat(fileno(stream), &file_info) && file_info.st_size > 0)
chunk_size = file_info.st_size;
chunk_size = static_cast<size_t>(file_info.st_size);
#endif // BUILDFLAG(IS_WIN)
// We need to attempt to read at EOF for feof flag to be set so here we
// use |chunk_size| + 1.
chunk_size = std::min<uint64_t>(chunk_size, max_size) + 1;
chunk_size = std::min(chunk_size, max_size) + 1;
size_t bytes_read_this_pass;
size_t bytes_read_so_far = 0;
bool read_status = true;
@ -345,7 +347,7 @@ bool GetFileSize(const FilePath& file_path, int64_t* file_size) {
bool TouchFile(const FilePath& path,
const Time& last_accessed,
const Time& last_modified) {
int flags = File::FLAG_OPEN | File::FLAG_WRITE_ATTRIBUTES;
uint32_t flags = File::FLAG_OPEN | File::FLAG_WRITE_ATTRIBUTES;
#if BUILDFLAG(IS_WIN)
// On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory.

@ -88,7 +88,7 @@ DWORD DeleteFileRecursive(const FilePath& path,
(recursive || !info.IsDirectory())) {
::SetFileAttributes(
current.value().c_str(),
info.find_data().dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
info.find_data().dwFileAttributes & ~DWORD{FILE_ATTRIBUTE_READONLY});
}
DWORD this_result = ERROR_SUCCESS;
@ -151,7 +151,7 @@ bool DoCopyFile(const FilePath& from_path,
return false;
}
if (attrs & FILE_ATTRIBUTE_READONLY) {
SetFileAttributes(dest, attrs & ~FILE_ATTRIBUTE_READONLY);
SetFileAttributes(dest, attrs & ~DWORD{FILE_ATTRIBUTE_READONLY});
}
return true;
}
@ -274,7 +274,7 @@ DWORD DoDeleteFile(const FilePath& path, bool recursive) {
// Clear the read-only bit if it is set.
if ((attr & FILE_ATTRIBUTE_READONLY) &&
!::SetFileAttributes(path.value().c_str(),
attr & ~FILE_ATTRIBUTE_READONLY)) {
attr & ~DWORD{FILE_ATTRIBUTE_READONLY})) {
// It's possible for |path| to be gone now under a race with other deleters.
return ReturnLastErrorOrSuccessOnNotFound();
}
@ -812,7 +812,9 @@ bool GetFileInfo(const FilePath& file_path, File::Info* results) {
ULARGE_INTEGER size;
size.HighPart = attr.nFileSizeHigh;
size.LowPart = attr.nFileSizeLow;
results->size = size.QuadPart;
// TODO(crbug.com/1333521): Change Info::size to uint64_t and eliminate this
// cast.
results->size = checked_cast<int64_t>(size.QuadPart);
results->is_directory =
(attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
@ -879,12 +881,15 @@ int ReadFile(const FilePath& filename, char* data, int max_size) {
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
NULL));
if (!file.is_valid())
if (!file.is_valid() || max_size < 0)
return -1;
DWORD read;
if (::ReadFile(file.get(), data, max_size, &read, NULL))
return read;
if (::ReadFile(file.get(), data, static_cast<DWORD>(max_size), &read, NULL)) {
// TODO(crbug.com/1333521): Change to return some type with a uint64_t size
// and eliminate this cast.
return checked_cast<int>(read);
}
return -1;
}
@ -894,15 +899,16 @@ int WriteFile(const FilePath& filename, const char* data, int size) {
win::ScopedHandle file(CreateFile(filename.value().c_str(), GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
NULL));
if (!file.is_valid()) {
DPLOG(WARNING) << "CreateFile failed for path " << filename.value();
if (!file.is_valid() || size < 0) {
DPLOG(WARNING) << "WriteFile failed for path " << filename.value();
return -1;
}
DWORD written;
BOOL result = ::WriteFile(file.get(), data, size, &written, NULL);
BOOL result =
::WriteFile(file.get(), data, static_cast<DWORD>(size), &written, NULL);
if (result && static_cast<int>(written) == size)
return written;
return static_cast<int>(written);
if (!result) {
// WriteFile failed.
@ -995,7 +1001,8 @@ bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
bool SetNonBlocking(int fd) {
unsigned long nonblocking = 1;
if (ioctlsocket(fd, FIONBIO, &nonblocking) == 0)
if (ioctlsocket(static_cast<SOCKET>(fd), static_cast<long>(FIONBIO),
&nonblocking) == 0)
return true;
return false;
}

@ -62,21 +62,25 @@ int File::Read(int64_t offset, char* data, int size) {
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
DCHECK(IsValid());
DCHECK(!async_);
if (size < 0)
if (size < 0 || offset < 0)
return -1;
SCOPED_FILE_TRACE_WITH_SIZE("Read", size);
LARGE_INTEGER offset_li;
offset_li.QuadPart = offset;
ULARGE_INTEGER offset_li;
offset_li.QuadPart = static_cast<uint64_t>(offset);
OVERLAPPED overlapped = {};
overlapped.Offset = offset_li.LowPart;
overlapped.OffsetHigh = offset_li.HighPart;
DWORD bytes_read;
if (::ReadFile(file_.get(), data, size, &bytes_read, &overlapped))
return bytes_read;
if (::ReadFile(file_.get(), data, static_cast<DWORD>(size), &bytes_read,
&overlapped)) {
// TODO(crbug.com/1333521): Change to return some type with a uint64_t size
// and eliminate this cast.
return checked_cast<int>(bytes_read);
}
if (ERROR_HANDLE_EOF == GetLastError())
return 0;
@ -93,8 +97,12 @@ int File::ReadAtCurrentPos(char* data, int size) {
SCOPED_FILE_TRACE_WITH_SIZE("ReadAtCurrentPos", size);
DWORD bytes_read;
if (::ReadFile(file_.get(), data, size, &bytes_read, NULL))
return bytes_read;
if (::ReadFile(file_.get(), data, static_cast<DWORD>(size), &bytes_read,
NULL)) {
// TODO(crbug.com/1333521): Change to return some type with a uint64_t size
// and eliminate this cast.
return checked_cast<int>(bytes_read);
}
if (ERROR_HANDLE_EOF == GetLastError())
return 0;
@ -115,19 +123,22 @@ int File::Write(int64_t offset, const char* data, int size) {
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
DCHECK(IsValid());
DCHECK(!async_);
if (size < 0 || offset < 0)
return -1;
SCOPED_FILE_TRACE_WITH_SIZE("Write", size);
LARGE_INTEGER offset_li;
offset_li.QuadPart = offset;
ULARGE_INTEGER offset_li;
offset_li.QuadPart = static_cast<uint64_t>(offset);
OVERLAPPED overlapped = {};
overlapped.Offset = offset_li.LowPart;
overlapped.OffsetHigh = offset_li.HighPart;
DWORD bytes_written;
if (::WriteFile(file_.get(), data, size, &bytes_written, &overlapped))
return bytes_written;
if (::WriteFile(file_.get(), data, static_cast<DWORD>(size), &bytes_written,
&overlapped))
return static_cast<int>(bytes_written);
return -1;
}
@ -142,8 +153,9 @@ int File::WriteAtCurrentPos(const char* data, int size) {
SCOPED_FILE_TRACE_WITH_SIZE("WriteAtCurrentPos", size);
DWORD bytes_written;
if (::WriteFile(file_.get(), data, size, &bytes_written, NULL))
return bytes_written;
if (::WriteFile(file_.get(), data, static_cast<DWORD>(size), &bytes_written,
NULL))
return static_cast<int>(bytes_written);
return -1;
}
@ -218,10 +230,12 @@ bool File::GetInfo(Info* info) {
if (!GetFileInformationByHandle(file_.get(), &file_info))
return false;
LARGE_INTEGER size;
ULARGE_INTEGER size;
size.HighPart = file_info.nFileSizeHigh;
size.LowPart = file_info.nFileSizeLow;
info->size = size.QuadPart;
// TODO(crbug.com/1333521): Change Info::size to uint64_t and eliminate this
// cast.
info->size = checked_cast<int64_t>(size.QuadPart);
info->is_directory =
(file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
info->is_symbolic_link = false; // Windows doesn't have symbolic links.
@ -341,7 +355,8 @@ File::Error File::OSErrorToFileError(DWORD last_error) {
case ERROR_DISK_CORRUPT: // The disk structure is corrupted and unreadable.
return FILE_ERROR_IO;
default:
UmaHistogramSparse("PlatformFile.UnknownErrors.Windows", last_error);
UmaHistogramSparse("PlatformFile.UnknownErrors.Windows",
static_cast<int>(last_error));
// This function should only be called for errors.
DCHECK_NE(static_cast<DWORD>(ERROR_SUCCESS), last_error);
return FILE_ERROR_FAILED;

@ -193,7 +193,8 @@ bool ImportantFileWriter::WriteFileAtomicallyImpl(const FilePath& path,
int bytes_written = 0;
for (const char *scan = data.data(), *const end = scan + data.length();
scan < end; scan += bytes_written) {
const int write_amount = std::min(kMaxWriteAmount, end - scan);
const int write_amount =
static_cast<int>(std::min(kMaxWriteAmount, end - scan));
bytes_written = tmp_file.WriteAtCurrentPos(scan, write_amount);
if (bytes_written != write_amount) {
DPLOG(WARNING) << "Failed to write " << write_amount << " bytes to temp "

@ -134,11 +134,13 @@ void MemoryMappedFile::CalculateVMAlignedBoundaries(int64_t start,
size_t* aligned_size,
int32_t* offset) {
// Sadly, on Windows, the mmap alignment is not just equal to the page size.
auto mask = SysInfo::VMAllocationGranularity() - 1;
uint64_t mask = SysInfo::VMAllocationGranularity() - 1;
DCHECK(IsValueInRangeForNumericType<int32_t>(mask));
*offset = start & mask;
*aligned_start = start & ~mask;
*aligned_size = (size + *offset + mask) & ~mask;
*offset = static_cast<int32_t>(static_cast<uint64_t>(start) & mask);
*aligned_start = static_cast<int64_t>(static_cast<uint64_t>(start) & ~mask);
// The DCHECK above means bit 31 is not set in `mask`, which in turn means
// *offset is positive. Therefore this cast is safe.
*aligned_size = (size + static_cast<size_t>(*offset) + mask) & ~mask;
}
#endif // !BUILDFLAG(IS_NACL)

@ -12,6 +12,7 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/numerics/checked_math.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/win/pe_image.h"
@ -61,7 +62,7 @@ bool MemoryMappedFile::MapFileRegionToMemory(
if (!file_.IsValid())
return false;
int flags = 0;
DWORD flags = 0;
ULARGE_INTEGER size = {};
switch (access) {
case READ_ONLY:
@ -83,7 +84,7 @@ bool MemoryMappedFile::MapFileRegionToMemory(
if (!file_mapping_.is_valid())
return false;
LARGE_INTEGER map_start = {};
ULARGE_INTEGER map_start = {};
SIZE_T map_size = 0;
int32_t data_offset = 0;
@ -105,17 +106,16 @@ bool MemoryMappedFile::MapFileRegionToMemory(
size_t ignored = 0U;
CalculateVMAlignedBoundaries(region.offset, region.size, &aligned_start,
&ignored, &data_offset);
int64_t full_map_size = region.size + data_offset;
base::CheckedNumeric<SIZE_T> full_map_size = region.size;
full_map_size += data_offset;
// Ensure that the casts below in the MapViewOfFile call are sane.
if (aligned_start < 0 || full_map_size < 0 ||
!IsValueInRangeForNumericType<SIZE_T>(
static_cast<uint64_t>(full_map_size))) {
if (aligned_start < 0 || !full_map_size.IsValid()) {
DLOG(ERROR) << "Region bounds are not valid for MapViewOfFile";
return false;
}
map_start.QuadPart = aligned_start;
map_size = static_cast<SIZE_T>(full_map_size);
map_start.QuadPart = static_cast<uint64_t>(aligned_start);
map_size = full_map_size.ValueOrDie();
length_ = region.size;
}

@ -43,7 +43,7 @@ ArcContentFileSystemAsyncFileUtil::~ArcContentFileSystemAsyncFileUtil() =
void ArcContentFileSystemAsyncFileUtil::CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) {
NOTIMPLEMENTED();
base::ThreadTaskRunnerHandle::Get()->PostTask(

@ -26,7 +26,7 @@ class ArcContentFileSystemAsyncFileUtil : public storage::AsyncFileUtil {
void CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) override;
void EnsureFileExists(
std::unique_ptr<storage::FileSystemOperationContext> context,

@ -295,7 +295,7 @@ ArcDocumentsProviderAsyncFileUtil::~ArcDocumentsProviderAsyncFileUtil() =
void ArcDocumentsProviderAsyncFileUtil::CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(nya): Implement this function if it is ever called.

@ -36,7 +36,7 @@ class ArcDocumentsProviderAsyncFileUtil : public storage::AsyncFileUtil {
void CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) override;
void EnsureFileExists(
std::unique_ptr<storage::FileSystemOperationContext> context,

@ -307,7 +307,7 @@ ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {}
void ProviderAsyncFileUtil::CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if ((file_flags & base::File::FLAG_CREATE) ||

@ -41,7 +41,7 @@ class ProviderAsyncFileUtil : public storage::AsyncFileUtil {
void CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) override;
void EnsureFileExists(
std::unique_ptr<storage::FileSystemOperationContext> context,

@ -308,7 +308,7 @@ bool DeviceMediaAsyncFileUtil::SupportsStreaming(
void DeviceMediaAsyncFileUtil::CreateOrOpen(
std::unique_ptr<FileSystemOperationContext> context,
const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
// Returns an error if any unsupported flag is found.

@ -49,7 +49,7 @@ class DeviceMediaAsyncFileUtil : public storage::AsyncFileUtil {
void CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) override;
void EnsureFileExists(
std::unique_ptr<storage::FileSystemOperationContext> context,

@ -209,7 +209,7 @@ base::File::Error NativeMediaFileUtil::BufferIsMediaHeader(
// static
void NativeMediaFileUtil::CreatedSnapshotFileForCreateOrOpen(
base::SequencedTaskRunner* media_task_runner,
int file_flags,
uint32_t file_flags,
storage::AsyncFileUtil::CreateOrOpenCallback callback,
base::File::Error result,
const base::File::Info& file_info,
@ -231,14 +231,15 @@ void NativeMediaFileUtil::CreatedSnapshotFileForCreateOrOpen(
void NativeMediaFileUtil::CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
// Returns an error if any unsupported flag is found.
if (file_flags & ~(base::File::FLAG_OPEN |
base::File::FLAG_READ |
base::File::FLAG_WRITE_ATTRIBUTES)) {
std::move(callback).Run(base::File(base::File::FILE_ERROR_SECURITY), base::OnceClosure());
std::move(callback).Run(base::File(base::File::FILE_ERROR_SECURITY),
base::OnceClosure());
return;
}
scoped_refptr<base::SequencedTaskRunner> task_runner = context->task_runner();

@ -44,7 +44,7 @@ class NativeMediaFileUtil : public storage::AsyncFileUtil {
// DeviceMediaAsyncFileUtil.
static void CreatedSnapshotFileForCreateOrOpen(
base::SequencedTaskRunner* media_task_runner,
int file_flags,
uint32_t file_flags,
storage::AsyncFileUtil::CreateOrOpenCallback callback,
base::File::Error result,
const base::File::Info& file_info,
@ -55,7 +55,7 @@ class NativeMediaFileUtil : public storage::AsyncFileUtil {
void CreateOrOpen(
std::unique_ptr<storage::FileSystemOperationContext> context,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) override;
void EnsureFileExists(
std::unique_ptr<storage::FileSystemOperationContext> context,

@ -296,7 +296,7 @@ void SyncableFileSystemOperation::TouchFile(
}
void SyncableFileSystemOperation::OpenFile(const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
OpenFileCallback callback) {
NOTREACHED();
}

@ -94,7 +94,7 @@ class SyncableFileSystemOperation : public storage::FileSystemOperation {
const base::Time& last_modified_time,
StatusCallback callback) override;
void OpenFile(const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
OpenFileCallback callback) override;
void Cancel(StatusCallback cancel_callback) override;
void CreateSnapshotFile(const storage::FileSystemURL& path,

@ -116,7 +116,7 @@ void OpenFileCallbackWrapperIO(
void CallOpenFile(
PepperFileSystemBrowserHost::GetOperationRunnerCallback get_runner,
const storage::FileSystemURL& url,
int file_flags,
uint32_t file_flags,
storage::FileSystemOperationRunner::OpenFileCallback callback) {
get_runner.Run()->OpenFile(
url, file_flags,
@ -182,7 +182,7 @@ int32_t PepperFileIOHost::OnHostMsgOpen(
if (rv != PP_OK)
return rv;
int platform_file_flags = 0;
uint32_t platform_file_flags = 0;
if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags,
&platform_file_flags))
return PP_ERROR_BADARGUMENT;
@ -246,7 +246,7 @@ int32_t PepperFileIOHost::OnHostMsgOpen(
void PepperFileIOHost::GotUIThreadStuffForInternalFileSystems(
ppapi::host::ReplyMessageContext reply_context,
int platform_file_flags,
uint32_t platform_file_flags,
UIThreadStuff ui_thread_stuff) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
resolved_render_process_id_ = ui_thread_stuff.resolved_render_process_id;
@ -309,7 +309,7 @@ void PepperFileIOHost::DidOpenInternalFile(
void PepperFileIOHost::GotResolvedRenderProcessId(
ppapi::host::ReplyMessageContext reply_context,
base::FilePath path,
int file_flags,
uint32_t file_flags,
base::ProcessId resolved_render_process_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
resolved_render_process_id_ = resolved_render_process_id;

@ -105,7 +105,7 @@ class PepperFileIOHost : public ppapi::host::ResourceHost,
void GotUIThreadStuffForInternalFileSystems(
ppapi::host::ReplyMessageContext reply_context,
int platform_file_flags,
uint32_t platform_file_flags,
UIThreadStuff ui_thread_stuff);
void DidOpenInternalFile(ppapi::host::ReplyMessageContext reply_context,
base::File file,
@ -113,7 +113,7 @@ class PepperFileIOHost : public ppapi::host::ResourceHost,
void GotResolvedRenderProcessId(
ppapi::host::ReplyMessageContext reply_context,
base::FilePath path,
int file_flags,
uint32_t file_flags,
base::ProcessId resolved_render_process_id);
void DidOpenQuotaFile(ppapi::host::ReplyMessageContext reply_context,

@ -36,7 +36,7 @@ int FileErrorToPepperError(base::File::Error error_code) {
}
bool PepperFileOpenFlagsToPlatformFileFlags(int32_t pp_open_flags,
int* flags_out) {
uint32_t* flags_out) {
bool pp_read = !!(pp_open_flags & PP_FILEOPENFLAG_READ);
bool pp_write = !!(pp_open_flags & PP_FILEOPENFLAG_WRITE);
bool pp_create = !!(pp_open_flags & PP_FILEOPENFLAG_CREATE);
@ -45,7 +45,7 @@ bool PepperFileOpenFlagsToPlatformFileFlags(int32_t pp_open_flags,
bool pp_append = !!(pp_open_flags & PP_FILEOPENFLAG_APPEND);
// Pepper allows Touch on any open file, so always set this Windows-only flag.
int flags = base::File::FLAG_WRITE_ATTRIBUTES;
uint32_t flags = base::File::FLAG_WRITE_ATTRIBUTES;
if (pp_read)
flags |= base::File::FLAG_READ;

@ -20,7 +20,7 @@ PPAPI_SHARED_EXPORT int FileErrorToPepperError(base::File::Error error_code);
// Returns |true| if okay.
PPAPI_SHARED_EXPORT bool PepperFileOpenFlagsToPlatformFileFlags(
int32_t pp_open_flags,
int* flags_out);
uint32_t* flags_out);
PPAPI_SHARED_EXPORT void FileInfoToPepperFileInfo(const base::File::Info& info,
PP_FileSystemType fs_type,

@ -101,7 +101,7 @@ class AsyncFileUtil {
//
virtual void CreateOrOpen(std::unique_ptr<FileSystemOperationContext> context,
const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) = 0;
// Ensures that the given |url| exist. This creates a empty new file

@ -177,7 +177,7 @@ AsyncFileUtilAdapter::~AsyncFileUtilAdapter() = default;
void AsyncFileUtilAdapter::CreateOrOpen(
std::unique_ptr<FileSystemOperationContext> context,
const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) {
FileSystemOperationContext* context_ptr = context.release();
base::PostTaskAndReplyWithResult(

@ -43,7 +43,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) AsyncFileUtilAdapter
// AsyncFileUtil overrides.
void CreateOrOpen(std::unique_ptr<FileSystemOperationContext> context,
const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
CreateOrOpenCallback callback) override;
void EnsureFileExists(std::unique_ptr<FileSystemOperationContext> context,
const FileSystemURL& url,

@ -347,7 +347,7 @@ class FileSystemOperation {
//
// This function is used only by Pepper as of writing.
virtual void OpenFile(const FileSystemURL& path,
int file_flags,
uint32_t file_flags,
OpenFileCallback callback) = 0;
// Creates a local snapshot file for a given |path| and returns the

@ -250,7 +250,7 @@ void FileSystemOperationImpl::TouchFile(const FileSystemURL& url,
}
void FileSystemOperationImpl::OpenFile(const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
OpenFileCallback callback) {
DCHECK(SetPendingOperationType(kOperationOpenFile));
@ -515,7 +515,7 @@ void FileSystemOperationImpl::DoTruncate(const FileSystemURL& url,
void FileSystemOperationImpl::DoOpenFile(const FileSystemURL& url,
OpenFileCallback callback,
int file_flags) {
uint32_t file_flags) {
async_file_util_->CreateOrOpen(
std::move(operation_context_), url, file_flags,
base::BindOnce(&DidOpenFile, file_system_context_, weak_ptr_,

@ -93,7 +93,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationImpl
const base::Time& last_modified_time,
StatusCallback callback) override;
void OpenFile(const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
OpenFileCallback callback) override;
void Cancel(StatusCallback cancel_callback) override;
void CreateSnapshotFile(const FileSystemURL& path,
@ -166,7 +166,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationImpl
int64_t length);
void DoOpenFile(const FileSystemURL& url,
OpenFileCallback callback,
int file_flags);
uint32_t file_flags);
// Callback for CreateFile for |exclusive|=true cases.
void DidEnsureFileExistsExclusive(StatusCallback callback,

@ -383,7 +383,7 @@ OperationID FileSystemOperationRunner::TouchFile(
}
OperationID FileSystemOperationRunner::OpenFile(const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
OpenFileCallback callback) {
base::File::Error error = base::File::FILE_OK;
std::unique_ptr<FileSystemOperation> operation =

@ -171,7 +171,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner {
// all situation e.g. it will always fail for the sandboxed system when in
// Incognito mode.
OperationID OpenFile(const FileSystemURL& url,
int file_flags,
uint32_t file_flags,
OpenFileCallback callback);
// Creates a local snapshot file for a given |url| and returns the

@ -134,7 +134,7 @@ NativeFileUtil::CopyOrMoveMode NativeFileUtil::CopyOrMoveModeForDestination(
}
base::File NativeFileUtil::CreateOrOpen(const base::FilePath& path,
int file_flags) {
uint32_t file_flags) {
if (!base::DirectoryExists(path.DirName())) {
// If its parent does not exist, should return NOT_FOUND error.
return base::File(base::File::FILE_ERROR_NOT_FOUND);

@ -42,7 +42,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) NativeFileUtil {
const FileSystemURL& dest_url,
bool copy);
static base::File CreateOrOpen(const base::FilePath& path, int file_flags);
static base::File CreateOrOpen(const base::FilePath& path,
uint32_t file_flags);
static base::File::Error EnsureFileExists(const base::FilePath& path,
bool* created);
static base::File::Error CreateDirectory(const base::FilePath& path,

@ -35,7 +35,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilDelegate {
const FileSystemURL& dest_url,
bool copy) = 0;
virtual base::File CreateOrOpen(const base::FilePath& path,
int file_flags) = 0;
uint32_t file_flags) = 0;
virtual base::File::Error EnsureFileExists(const base::FilePath& path,
bool* created) = 0;
virtual base::File::Error CreateDirectory(const base::FilePath& path,

@ -48,7 +48,7 @@ ObfuscatedFileUtilDiskDelegate::CopyOrMoveModeForDestination(
base::File ObfuscatedFileUtilDiskDelegate::CreateOrOpen(
const base::FilePath& path,
int file_flags) {
uint32_t file_flags) {
return NativeFileUtil::CreateOrOpen(path, file_flags);
}

@ -35,7 +35,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilDiskDelegate
NativeFileUtil::CopyOrMoveMode CopyOrMoveModeForDestination(
const FileSystemURL& dest_url,
bool copy) override;
base::File CreateOrOpen(const base::FilePath& path, int file_flags) override;
base::File CreateOrOpen(const base::FilePath& path,
uint32_t file_flags) override;
base::File::Error EnsureFileExists(const base::FilePath& path,
bool* created) override;
base::File::Error CreateDirectory(const base::FilePath& path,

@ -234,7 +234,7 @@ bool ObfuscatedFileUtilMemoryDelegate::PathExists(const base::FilePath& path) {
base::File ObfuscatedFileUtilMemoryDelegate::CreateOrOpen(
const base::FilePath& path,
int file_flags) {
uint32_t file_flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO:(https://crbug.com/936722): Once the output of this function is
// changed to base::File::Error, it can use CreateOrOpenInternal to perform
@ -244,7 +244,7 @@ base::File ObfuscatedFileUtilMemoryDelegate::CreateOrOpen(
void ObfuscatedFileUtilMemoryDelegate::CreateOrOpenInternal(
const DecomposedPath& dp,
int file_flags) {
uint32_t file_flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!dp.entry) {
dp.parent->directory_content.emplace(dp.components.back(), Entry::kFile);

@ -58,7 +58,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilMemoryDelegate
NativeFileUtil::CopyOrMoveMode CopyOrMoveModeForDestination(
const FileSystemURL& dest_url,
bool copy) override;
base::File CreateOrOpen(const base::FilePath& path, int file_flags) override;
base::File CreateOrOpen(const base::FilePath& path,
uint32_t file_flags) override;
base::File::Error EnsureFileExists(const base::FilePath& path,
bool* created) override;
base::File::Error CreateDirectory(const base::FilePath& path,
@ -120,7 +121,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilMemoryDelegate
absl::optional<DecomposedPath> ParsePath(const base::FilePath& path);
// Creates or opens a file specified in |dp|.
void CreateOrOpenInternal(const DecomposedPath& dp, int file_flags);
void CreateOrOpenInternal(const DecomposedPath& dp, uint32_t file_flags);
// Moves a directory from |src_dp| to |dest_dp|.
bool MoveDirectoryInternal(const DecomposedPath& src_dp,