| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "core/html/ImageData.h" | 30 #include "core/html/ImageData.h" |
| 31 | 31 |
| 32 namespace WebCore { | 32 namespace WebCore { |
| 33 | 33 |
| 34 PassRefPtr<ImageData> ImageData::create(const IntSize& size) | 34 PassRefPtr<ImageData> ImageData::create(const IntSize& size) |
| 35 { | 35 { |
| 36 Checked<int, RecordOverflow> dataSize = 4; | 36 Checked<int, RecordOverflow> dataSize = 4; |
| 37 dataSize *= size.width(); | 37 dataSize *= size.width(); |
| 38 dataSize *= size.height(); | 38 dataSize *= size.height(); |
| 39 if (dataSize.hasOverflowed()) | 39 if (dataSize.hasOverflowed()) |
| 40 return 0; | 40 return nullptr; |
| 41 | 41 |
| 42 return adoptRef(new ImageData(size)); | 42 return adoptRef(new ImageData(size)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 PassRefPtr<ImageData> ImageData::create(const IntSize& size, PassRefPtr<Uint8Cla
mpedArray> byteArray) | 45 PassRefPtr<ImageData> ImageData::create(const IntSize& size, PassRefPtr<Uint8Cla
mpedArray> byteArray) |
| 46 { | 46 { |
| 47 Checked<int, RecordOverflow> dataSize = 4; | 47 Checked<int, RecordOverflow> dataSize = 4; |
| 48 dataSize *= size.width(); | 48 dataSize *= size.width(); |
| 49 dataSize *= size.height(); | 49 dataSize *= size.height(); |
| 50 if (dataSize.hasOverflowed()) | 50 if (dataSize.hasOverflowed()) |
| 51 return 0; | 51 return nullptr; |
| 52 | 52 |
| 53 if (dataSize.unsafeGet() < 0 | 53 if (dataSize.unsafeGet() < 0 |
| 54 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) | 54 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) |
| 55 return 0; | 55 return nullptr; |
| 56 | 56 |
| 57 return adoptRef(new ImageData(size, byteArray)); | 57 return adoptRef(new ImageData(size, byteArray)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 ImageData::ImageData(const IntSize& size) | 60 ImageData::ImageData(const IntSize& size) |
| 61 : m_size(size) | 61 : m_size(size) |
| 62 , m_data(Uint8ClampedArray::createUninitialized(size.width() * size.height()
* 4)) | 62 , m_data(Uint8ClampedArray::createUninitialized(size.width() * size.height()
* 4)) |
| 63 { | 63 { |
| 64 ScriptWrappable::init(this); | 64 ScriptWrappable::init(this); |
| 65 } | 65 } |
| 66 | 66 |
| 67 ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra
y) | 67 ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra
y) |
| 68 : m_size(size) | 68 : m_size(size) |
| 69 , m_data(byteArray) | 69 , m_data(byteArray) |
| 70 { | 70 { |
| 71 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); | 71 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); |
| 72 ScriptWrappable::init(this); | 72 ScriptWrappable::init(this); |
| 73 } | 73 } |
| 74 | 74 |
| 75 } | 75 } |
| 76 | 76 |
| OLD | NEW |