Index: chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js |
diff --git a/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js b/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js |
index 020c772c849df1e94f07bcba46aad5888b11fd50..24abde29f7aef248962536ab3fb8f43f32c88732 100644 |
--- a/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js |
+++ b/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js |
@@ -12,6 +12,13 @@ var fileSystemNatives = requireNative('file_system_natives'); |
var GetDOMError = fileSystemNatives.GetDOMError; |
/** |
+ * Maximum size of the thumbnail in bytes. |
+ * @type {number} |
+ * @const |
+ */ |
+var METADATA_THUMBNAIL_SIZE_LIMIT = 32 * 1024 * 1024; |
+ |
+/** |
* Annotates a date with its serialized value. |
* @param {Date} date Input date. |
* @return {Date} Date with an extra <code>value</code> attribute. |
@@ -24,6 +31,22 @@ function annotateDate(date) { |
} |
/** |
+ * Verifies if the passed image URI is valid. |
+ * @param {*} uri Image URI. |
+ * @return {boolean} True if valid, valse otherwise. |
+ */ |
+function verifyImageURI(uri) { |
+ // The URI is specified by a user, so the type may be incorrect. |
+ if (typeof uri != 'string' && !(uri instanceof String)) |
+ return false; |
+ |
+ var uriLowerCase = uri.toLowerCase(); |
hirono
2014/08/29 03:58:32
uri.substr(0, 20).toLowerCase() may be good for pe
mtomasz
2014/08/29 05:20:26
Good point. I optimized it in C++, but forgot abou
|
+ return uriLowerCase.indexOf('data:image/png;') == 0 || |
+ uriLowerCase.indexOf('data:image/jpeg;') == 0 || |
+ uriLowerCase.indexOf('data:image/webp;') == 0; |
+} |
+ |
+/** |
* Annotates an entry metadata by serializing its modifiedTime value. |
* @param {EntryMetadata} metadata Input metadata. |
* @return {EntryMetadata} metadata Annotated metadata, which can be passed |
@@ -38,6 +61,8 @@ function annotateMetadata(metadata) { |
}; |
if ('mimeType' in metadata) |
result.mimeType = metadata.mimeType; |
+ if ('thumbnail' in metadata) |
+ result.thumbnail = metadata.thumbnail; |
return result; |
} |
@@ -141,6 +166,25 @@ eventBindings.registerArgumentMassager( |
var executionStart = Date.now(); |
var options = args[0]; |
var onSuccessCallback = function(metadata) { |
+ // It is invalid to return a thumbnail when it's not requested. The |
+ // restriction is added in order to avoid fetching the thumbnail while |
+ // it's not needed. |
+ if (!options.thumbnail && metadata.thumbnail) { |
+ fileSystemProviderInternal.operationRequestedError( |
+ options.fileSystemId, options.requestId, 'FAILED', |
+ Date.now() - executionStart); |
+ throw new Error('Thumbnail data provided, but not requested.'); |
+ } |
+ |
+ // Check the format and size. Note, that in the C++ layer, there is |
+ // another sanity check to avoid passing any evil URL. |
+ if ('thumbnail' in metadata && !verifyImageURI(metadata.thumbnail)) |
+ throw new Error('Thumbnail format invalid.'); |
+ if ('thumbnail' in metadata && |
+ metadata.thumbnail.length > METADATA_THUMBNAIL_SIZE_LIMIT) { |
+ throw new Error('Thumbnail data too large.'); |
+ } |
+ |
fileSystemProviderInternal.getMetadataRequestedSuccess( |
options.fileSystemId, |
options.requestId, |
@@ -162,6 +206,16 @@ eventBindings.registerArgumentMassager( |
var options = args[0]; |
var onSuccessCallback = function(entries, hasNext) { |
var annotatedEntries = entries.map(annotateMetadata); |
+ // It is invalid to return a thumbnail when it's not requested. |
+ annotatedEntries.forEach(function(metadata) { |
+ if (metadata.thumbnail) { |
+ fileSystemProviderInternal.operationRequestedError( |
+ options.fileSystemId, options.requestId, 'FAILED', |
+ Date.now() - executionStart); |
+ throw new Error( |
+ 'Thumbnails must not be provided when reading a directory.'); |
+ } |
+ }); |
fileSystemProviderInternal.readDirectoryRequestedSuccess( |
options.fileSystemId, options.requestId, annotatedEntries, hasNext, |
Date.now() - executionStart); |