diff options
author | tschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 00:41:31 +0000 |
---|---|---|
committer | tschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 00:41:31 +0000 |
commit | 4f4cdd77f20dc52f349b075d2390d3df33be6f9d (patch) | |
tree | 5a9ef3ba541f26e5563988bb18f1811e42d23cc9 /o3d/import | |
parent | 42d25adafb088eebeae625b06ef8b48ae7dee97b (diff) | |
download | chromium_src-4f4cdd77f20dc52f349b075d2390d3df33be6f9d.zip chromium_src-4f4cdd77f20dc52f349b075d2390d3df33be6f9d.tar.gz chromium_src-4f4cdd77f20dc52f349b075d2390d3df33be6f9d.tar.bz2 |
Gut the temp file flushing feature of RawData, because it is a security risk. The OS should automatically flush the pages from physical memory anyways.
TEST=(Linux FF 3.0) ping pong, beach demo, prince IO, stenciled teapot, simple scene viewer, sobel edge detection shader
BUG=none
Review URL: http://codereview.chromium.org/3064028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/import')
-rw-r--r-- | o3d/import/cross/raw_data.cc | 158 | ||||
-rw-r--r-- | o3d/import/cross/raw_data.h | 32 |
2 files changed, 13 insertions, 177 deletions
diff --git a/o3d/import/cross/raw_data.cc b/o3d/import/cross/raw_data.cc index 2cc8d7f..e5c0246 100644 --- a/o3d/import/cross/raw_data.cc +++ b/o3d/import/cross/raw_data.cc @@ -34,19 +34,12 @@ // by the progressive streaming archive system #include "import/cross/raw_data.h" -#include "base/file_util.h" -#include "utils/cross/file_path_utils.h" + #include "base/file_path.h" #include "base/file_util.h" +#include "core/cross/error.h" #include "utils/cross/dataurl.h" - -#ifdef OS_MACOSX -#include <CoreFoundation/CoreFoundation.h> -#endif - -#ifdef OS_WIN -#include <rpc.h> -#endif +#include "utils/cross/file_path_utils.h" using file_util::OpenFile; using file_util::CloseFile; @@ -167,31 +160,10 @@ const uint8 *RawData::GetData() const { // Return data immediately if we have it if (data_.get()) { return data_.get(); - } - - // We need to load the data from the cache file - if (temp_filepath_.empty()) { + } else { DLOG(ERROR) << "cannot retrieve data object - it has been released"; return NULL; } - - FILE *tempfile = file_util::OpenFile(temp_filepath_, "rb"); - if (!tempfile) { - DLOG(ERROR) << "cached data file cannot be opened"; - return NULL; - } - - data_.reset(new uint8[length_]); - size_t bytes_read = fread(data_.get(), 1, length_, tempfile); - - if (bytes_read != length_) { - DLOG(ERROR) << "error reading cached data file"; - data_.reset(); - } - - file_util::CloseFile(tempfile); - - return data_.get(); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -299,38 +271,8 @@ String RawData::StringValue() const { } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -void RawData::Flush() { - // Only create the temp file if it doesn't already exist - if (data_.get() && temp_filepath_.empty()) { - if (GetTempFilePathFromURI(uri_, &temp_filepath_)) { - FILE *tempfile = file_util::OpenFile(temp_filepath_, "wb"); - - if (tempfile) { - if (GetLength() != fwrite(data_.get(), 1, GetLength(), tempfile)) { - DLOG(ERROR) << "error writing cached data file"; - } - file_util::CloseFile(tempfile); - - // Now that the data is cached, free it - data_.reset(); - } else { - DLOG(ERROR) << "error creating cached data file"; - temp_filepath_ = FilePath(); - } - } - } -} - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -const FilePath& RawData::GetTempFilePath() { - Flush(); // writes temp file if it's not already written - return temp_filepath_; -} - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void RawData::Discard() { data_.reset(); - DeleteTempFile(); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -346,96 +288,4 @@ bool RawData::IsOffsetLengthValid(size_t offset, size_t length) const { return true; } -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -void RawData::DeleteTempFile() { - if (!temp_filepath_.empty()) { - file_util::Delete(temp_filepath_, false); - temp_filepath_ = FilePath(); - } -} - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -static String GetUUIDString() { -#ifdef OS_WIN - // now generate a GUID - UUID guid = {0}; - UuidCreate(&guid); - - // and format into a wide-string - char guid_string[37]; -#if defined(OS_WIN) -#define snprintf _snprintf -#endif - snprintf( - guid_string, sizeof(guid_string) / sizeof(guid_string[0]), - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - guid.Data1, guid.Data2, guid.Data3, - guid.Data4[0], guid.Data4[1], guid.Data4[2], - guid.Data4[3], guid.Data4[4], guid.Data4[5], - guid.Data4[6], guid.Data4[7]); - - return guid_string; -#endif - -#ifdef OS_MACOSX - CFUUIDRef uuid = CFUUIDCreate(NULL); - CFStringRef uuid_string_ref = CFUUIDCreateString(NULL, uuid); - CFRelease(uuid); - - char uuid_string[64]; - uuid_string[0] = 0; // null-terminate, in case CFStringGetCString() fails - CFStringGetCString(uuid_string_ref, - uuid_string, - sizeof(uuid_string), - kCFStringEncodingUTF8); - CFRelease(uuid_string_ref); - - - return uuid_string; -#endif - -#ifdef OS_LINUX - static unsigned int index = 0; - char uuid[18] = {0}; - unsigned int pid = getpid(); - snprintf(uuid, 18, "%08x-%08x", pid, index++); - return String(uuid); -#endif -} - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -bool RawData::GetTempFilePathFromURI(const String &uri, - FilePath *temp_fullpath) { - if (!temp_fullpath) return false; - - // We use a UUID here to avoid any possible collisions with other tempfiles - // which have been or will be written sharing the same basic name - - FilePath temp_path; - if (!file_util::GetTempDir(&temp_path)) { - return false; - } - - String uuid_string = GetUUIDString(); - - // format the temp file basename - String filename; - - // try to retain the original file suffix (.jpg, etc.) - std::string::size_type dot_position = uri.rfind('.'); - if (dot_position != std::string::npos) { - filename = uuid_string + uri.substr(dot_position); - } else { - filename = uuid_string; - } - - // Construct the full pathname - FilePath fullpath = temp_path; - fullpath = fullpath.AppendASCII(filename); - - if (temp_fullpath) *temp_fullpath = fullpath; - - return true; -} - } // namespace o3d diff --git a/o3d/import/cross/raw_data.h b/o3d/import/cross/raw_data.h index 96ea3f4..9f433cc 100644 --- a/o3d/import/cross/raw_data.h +++ b/o3d/import/cross/raw_data.h @@ -39,12 +39,8 @@ #ifndef O3D_IMPORT_CROSS_RAW_DATA_H_ #define O3D_IMPORT_CROSS_RAW_DATA_H_ -#include "base/file_path.h" #include "base/scoped_ptr.h" -#include "core/cross/error.h" #include "core/cross/param_object.h" -#include "core/cross/param.h" -#include "core/cross/types.h" namespace o3d { @@ -83,31 +79,25 @@ class RawData : public ParamObject { const String& uri() const { return uri_; } void set_uri(const String& uri) { uri_ = uri; } - // If the data is still around - // (ie, Discard has not been called), then, if it has not been written - // to a temp file write it to a temp file - void Flush(); + // Historically this wrote the data out to a temp file and deleted it from + // memory, but that functionality was removed due to security concerns. In any + // event, a RawData object that is big enough to be worth removing from memory + // will occupy multiple complete pages which won't be in the process's working + // set, so the OS will eventually remove it from the physical memory anyway + // and bring it back in when we next access it. + void Flush() {} - // calls Flush() if necessary and returns the path to the temp file - // if Discard() has already been called then returns an "empty" FilePath - const FilePath& GetTempFilePath(); - - // deletes the data which means IF the data is in memory it is - // freed. If there is a temp file it is deleted. + // deletes the data void Discard(); bool IsOffsetLengthValid(size_t offset, size_t length) const; private: String uri_; - mutable scoped_array<uint8> data_; + scoped_array<uint8> data_; size_t length_; - FilePath temp_filepath_; bool allow_string_value_; - // Deletes temp file if it exists - void DeleteTempFile(); - RawData(ServiceLocator* service_locator, const String &uri, const void *data, @@ -122,10 +112,6 @@ class RawData : public ParamObject { friend class IClassManager; friend class Pack; - // Returns |true| on success - bool GetTempFilePathFromURI(const String &uri, - FilePath *temp_fullpath); - O3D_DECL_CLASS(RawData, ParamObject) DISALLOW_COPY_AND_ASSIGN(RawData); }; |