OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/nacl_message_scanner.h" | 5 #include "ppapi/proxy/nacl_message_scanner.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 untrusted_msg, ¶ms, &nested_msg)) | 374 untrusted_msg, ¶ms, &nested_msg)) |
375 return; | 375 return; |
376 | 376 |
377 switch (nested_msg.type()) { | 377 switch (nested_msg.type()) { |
378 case PpapiHostMsg_FileIO_Close::ID: { | 378 case PpapiHostMsg_FileIO_Close::ID: { |
379 FileIOMap::iterator it = files_.find(params.pp_resource()); | 379 FileIOMap::iterator it = files_.find(params.pp_resource()); |
380 if (it == files_.end()) | 380 if (it == files_.end()) |
381 return; | 381 return; |
382 // Audit FileIO Close messages to make sure the plugin reports an | 382 // Audit FileIO Close messages to make sure the plugin reports an |
383 // accurate file size. | 383 // accurate file size. |
384 int64_t max_written_offset = 0; | 384 FileGrowth file_growth; |
385 if (!UnpackMessage<PpapiHostMsg_FileIO_Close>( | 385 if (!UnpackMessage<PpapiHostMsg_FileIO_Close>( |
386 nested_msg, &max_written_offset)) | 386 nested_msg, &file_growth)) |
387 return; | 387 return; |
388 | 388 |
389 int64_t trusted_max_written_offset = it->second->max_written_offset(); | 389 int64_t trusted_max_written_offset = it->second->max_written_offset(); |
390 delete it->second; | 390 delete it->second; |
391 files_.erase(it); | 391 files_.erase(it); |
392 // If the plugin is under-reporting, rewrite the message with the | 392 // If the plugin is under-reporting, rewrite the message with the |
393 // trusted value. | 393 // trusted value. |
394 if (trusted_max_written_offset > max_written_offset) { | 394 if (trusted_max_written_offset > file_growth.max_written_offset) { |
395 new_msg_ptr->reset( | 395 new_msg_ptr->reset( |
396 new PpapiHostMsg_ResourceCall( | 396 new PpapiHostMsg_ResourceCall( |
397 params, | 397 params, |
398 PpapiHostMsg_FileIO_Close(trusted_max_written_offset))); | 398 PpapiHostMsg_FileIO_Close( |
| 399 FileGrowth(trusted_max_written_offset, 0)))); |
399 } | 400 } |
400 } | 401 } |
401 case PpapiHostMsg_FileIO_SetLength::ID: { | 402 case PpapiHostMsg_FileIO_SetLength::ID: { |
402 FileIOMap::iterator it = files_.find(params.pp_resource()); | 403 FileIOMap::iterator it = files_.find(params.pp_resource()); |
403 if (it == files_.end()) | 404 if (it == files_.end()) |
404 return; | 405 return; |
405 // Audit FileIO SetLength messages to make sure the plugin is within | 406 // Audit FileIO SetLength messages to make sure the plugin is within |
406 // the current quota reservation. In addition, deduct the file size | 407 // the current quota reservation. In addition, deduct the file size |
407 // increase from the quota reservation. | 408 // increase from the quota reservation. |
408 int64_t length = 0; | 409 int64_t length = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
422 new PpapiHostMsg_ResourceCall( | 423 new PpapiHostMsg_ResourceCall( |
423 params, | 424 params, |
424 PpapiHostMsg_FileIO_SetLength(-1))); | 425 PpapiHostMsg_FileIO_SetLength(-1))); |
425 } | 426 } |
426 break; | 427 break; |
427 } | 428 } |
428 case PpapiHostMsg_FileSystem_ReserveQuota::ID: { | 429 case PpapiHostMsg_FileSystem_ReserveQuota::ID: { |
429 // Audit FileSystem ReserveQuota messages to make sure the plugin | 430 // Audit FileSystem ReserveQuota messages to make sure the plugin |
430 // reports accurate file sizes. | 431 // reports accurate file sizes. |
431 int64_t amount = 0; | 432 int64_t amount = 0; |
432 FileOffsetMap max_written_offsets; | 433 FileGrowthMap file_growths; |
433 if (!UnpackMessage<PpapiHostMsg_FileSystem_ReserveQuota>( | 434 if (!UnpackMessage<PpapiHostMsg_FileSystem_ReserveQuota>( |
434 nested_msg, &amount, &max_written_offsets)) | 435 nested_msg, &amount, &file_growths)) |
435 return; | 436 return; |
436 | 437 |
437 bool audit_failed = false; | 438 bool audit_failed = false; |
438 for (FileOffsetMap::iterator it = max_written_offsets.begin(); | 439 for (FileGrowthMap::iterator it = file_growths.begin(); |
439 it != max_written_offsets.end(); ++it) { | 440 it != file_growths.end(); ++it) { |
440 FileIOMap::iterator file_it = files_.find(it->first); | 441 FileIOMap::iterator file_it = files_.find(it->first); |
441 if (file_it == files_.end()) | 442 if (file_it == files_.end()) |
442 continue; | 443 continue; |
443 int64_t trusted_max_written_offset = | 444 int64_t trusted_max_written_offset = |
444 file_it->second->max_written_offset(); | 445 file_it->second->max_written_offset(); |
445 if (trusted_max_written_offset > it->second) { | 446 if (trusted_max_written_offset > it->second.max_written_offset) { |
446 audit_failed = true; | 447 audit_failed = true; |
447 it->second = trusted_max_written_offset; | 448 it->second.max_written_offset = trusted_max_written_offset; |
| 449 } |
| 450 if (it->second.append_mode_write_amount < 0) { |
| 451 audit_failed = true; |
| 452 it->second.append_mode_write_amount = 0; |
448 } | 453 } |
449 } | 454 } |
450 if (audit_failed) { | 455 if (audit_failed) { |
451 new_msg_ptr->reset( | 456 new_msg_ptr->reset( |
452 new PpapiHostMsg_ResourceCall( | 457 new PpapiHostMsg_ResourceCall( |
453 params, | 458 params, |
454 PpapiHostMsg_FileSystem_ReserveQuota( | 459 PpapiHostMsg_FileSystem_ReserveQuota( |
455 amount, max_written_offsets))); | 460 amount, file_growths))); |
456 } | 461 } |
457 break; | 462 break; |
458 } | 463 } |
459 case PpapiHostMsg_ResourceDestroyed::ID: { | 464 case PpapiHostMsg_ResourceDestroyed::ID: { |
460 // Audit resource destroyed messages to release FileSystems. | 465 // Audit resource destroyed messages to release FileSystems. |
461 PP_Resource resource; | 466 PP_Resource resource; |
462 if (!UnpackMessage<PpapiHostMsg_ResourceDestroyed>( | 467 if (!UnpackMessage<PpapiHostMsg_ResourceDestroyed>( |
463 nested_msg, &resource)) | 468 nested_msg, &resource)) |
464 return; | 469 return; |
465 FileSystemMap::iterator fs_it = file_systems_.find(resource); | 470 FileSystemMap::iterator fs_it = file_systems_.find(resource); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 files_.insert(std::make_pair( | 516 files_.insert(std::make_pair( |
512 resource, | 517 resource, |
513 new FileIO(file_system, max_written_offset))); | 518 new FileIO(file_system, max_written_offset))); |
514 } | 519 } |
515 } | 520 } |
516 break; | 521 break; |
517 } | 522 } |
518 case PpapiPluginMsg_FileSystem_ReserveQuotaReply::ID: { | 523 case PpapiPluginMsg_FileSystem_ReserveQuotaReply::ID: { |
519 // The amount of reserved quota for a FileSystem was refreshed. | 524 // The amount of reserved quota for a FileSystem was refreshed. |
520 int64_t amount = 0; | 525 int64_t amount = 0; |
521 FileOffsetMap max_written_offsets; | 526 FileSizeMap file_sizes; |
522 if (ppapi::UnpackMessage<PpapiPluginMsg_FileSystem_ReserveQuotaReply>( | 527 if (ppapi::UnpackMessage<PpapiPluginMsg_FileSystem_ReserveQuotaReply>( |
523 msg, &amount, &max_written_offsets)) { | 528 msg, &amount, &file_sizes)) { |
524 FileSystemMap::iterator it = file_systems_.find(resource); | 529 FileSystemMap::iterator it = file_systems_.find(resource); |
525 DCHECK(it != file_systems_.end()); | 530 DCHECK(it != file_systems_.end()); |
526 it->second->UpdateReservedQuota(amount); | 531 it->second->UpdateReservedQuota(amount); |
527 | 532 |
528 FileOffsetMap::const_iterator offset_it = max_written_offsets.begin(); | 533 FileSizeMap::const_iterator offset_it = file_sizes.begin(); |
529 for (; offset_it != max_written_offsets.end(); ++offset_it) { | 534 for (; offset_it != file_sizes.end(); ++offset_it) { |
530 FileIOMap::iterator fio_it = files_.find(offset_it->first); | 535 FileIOMap::iterator fio_it = files_.find(offset_it->first); |
531 DCHECK(fio_it != files_.end()); | 536 DCHECK(fio_it != files_.end()); |
532 if (fio_it != files_.end()) | 537 if (fio_it != files_.end()) |
533 fio_it->second->SetMaxWrittenOffset(offset_it->second); | 538 fio_it->second->SetMaxWrittenOffset(offset_it->second); |
534 } | 539 } |
535 } | 540 } |
536 break; | 541 break; |
537 } | 542 } |
538 } | 543 } |
539 } | 544 } |
540 | 545 |
541 } // namespace proxy | 546 } // namespace proxy |
542 } // namespace ppapi | 547 } // namespace ppapi |
OLD | NEW |