diff options
| author | 2018-10-25 12:22:10 -0400 | |
|---|---|---|
| committer | 2018-10-25 12:22:10 -0400 | |
| commit | 0634aee2676f4863385172352a041804bdf113cd (patch) | |
| tree | d48b0b0adfe128783b1911f6ca22a69924887d06 | |
| parent | Merge pull request #1577 from lioncash/err (diff) | |
| parent | service/acc: Move fallback image to file scope (diff) | |
| download | yuzu-0634aee2676f4863385172352a041804bdf113cd.tar.gz yuzu-0634aee2676f4863385172352a041804bdf113cd.tar.xz yuzu-0634aee2676f4863385172352a041804bdf113cd.zip | |
Merge pull request #1576 from lioncash/acc-warn
service/acc: Silence compiler truncation warnings
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index cf065c2e0..c6437a671 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -21,8 +21,6 @@ | |||
| 21 | 21 | ||
| 22 | namespace Service::Account { | 22 | namespace Service::Account { |
| 23 | 23 | ||
| 24 | constexpr u32 MAX_JPEG_IMAGE_SIZE = 0x20000; | ||
| 25 | |||
| 26 | // TODO: RE this structure | 24 | // TODO: RE this structure |
| 27 | struct UserData { | 25 | struct UserData { |
| 28 | INSERT_PADDING_WORDS(1); | 26 | INSERT_PADDING_WORDS(1); |
| @@ -34,11 +32,29 @@ struct UserData { | |||
| 34 | }; | 32 | }; |
| 35 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); | 33 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); |
| 36 | 34 | ||
| 35 | // Smallest JPEG https://github.com/mathiasbynens/small/blob/master/jpeg.jpg | ||
| 36 | // used as a backup should the one on disk not exist | ||
| 37 | constexpr u32 backup_jpeg_size = 107; | ||
| 38 | constexpr std::array<u8, backup_jpeg_size> backup_jpeg{{ | ||
| 39 | 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, | ||
| 40 | 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, | ||
| 41 | 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, | ||
| 42 | 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, | ||
| 43 | 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, | ||
| 44 | 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, | ||
| 45 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | ||
| 46 | }}; | ||
| 47 | |||
| 37 | static std::string GetImagePath(UUID uuid) { | 48 | static std::string GetImagePath(UUID uuid) { |
| 38 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | 49 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + |
| 39 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; | 50 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; |
| 40 | } | 51 | } |
| 41 | 52 | ||
| 53 | static constexpr u32 SanitizeJPEGSize(std::size_t size) { | ||
| 54 | constexpr std::size_t max_jpeg_image_size = 0x20000; | ||
| 55 | return static_cast<u32>(std::min(size, max_jpeg_image_size)); | ||
| 56 | } | ||
| 57 | |||
| 42 | class IProfile final : public ServiceFramework<IProfile> { | 58 | class IProfile final : public ServiceFramework<IProfile> { |
| 43 | public: | 59 | public: |
| 44 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) | 60 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) |
| @@ -86,43 +102,29 @@ private: | |||
| 86 | 102 | ||
| 87 | void LoadImage(Kernel::HLERequestContext& ctx) { | 103 | void LoadImage(Kernel::HLERequestContext& ctx) { |
| 88 | LOG_DEBUG(Service_ACC, "called"); | 104 | LOG_DEBUG(Service_ACC, "called"); |
| 89 | // smallest jpeg https://github.com/mathiasbynens/small/blob/master/jpeg.jpg | ||
| 90 | // used as a backup should the one on disk not exist | ||
| 91 | constexpr u32 backup_jpeg_size = 107; | ||
| 92 | static constexpr std::array<u8, backup_jpeg_size> backup_jpeg{ | ||
| 93 | 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
| 94 | 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, | ||
| 95 | 0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, | ||
| 96 | 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, | ||
| 97 | 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, | ||
| 98 | 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x11, 0x00, | ||
| 99 | 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01, | ||
| 100 | 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | ||
| 101 | }; | ||
| 102 | 105 | ||
| 103 | IPC::ResponseBuilder rb{ctx, 3}; | 106 | IPC::ResponseBuilder rb{ctx, 3}; |
| 104 | rb.Push(RESULT_SUCCESS); | 107 | rb.Push(RESULT_SUCCESS); |
| 105 | 108 | ||
| 106 | const FileUtil::IOFile image(GetImagePath(user_id), "rb"); | 109 | const FileUtil::IOFile image(GetImagePath(user_id), "rb"); |
| 107 | |||
| 108 | if (!image.IsOpen()) { | 110 | if (!image.IsOpen()) { |
| 109 | LOG_WARNING(Service_ACC, | 111 | LOG_WARNING(Service_ACC, |
| 110 | "Failed to load user provided image! Falling back to built-in backup..."); | 112 | "Failed to load user provided image! Falling back to built-in backup..."); |
| 111 | ctx.WriteBuffer(backup_jpeg); | 113 | ctx.WriteBuffer(backup_jpeg); |
| 112 | rb.Push<u32>(backup_jpeg_size); | 114 | rb.Push<u32>(backup_jpeg_size); |
| 113 | } else { | 115 | return; |
| 114 | const auto size = std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE); | ||
| 115 | std::vector<u8> buffer(size); | ||
| 116 | image.ReadBytes(buffer.data(), buffer.size()); | ||
| 117 | |||
| 118 | ctx.WriteBuffer(buffer.data(), buffer.size()); | ||
| 119 | rb.Push<u32>(buffer.size()); | ||
| 120 | } | 116 | } |
| 117 | |||
| 118 | const u32 size = SanitizeJPEGSize(image.GetSize()); | ||
| 119 | std::vector<u8> buffer(size); | ||
| 120 | image.ReadBytes(buffer.data(), buffer.size()); | ||
| 121 | |||
| 122 | ctx.WriteBuffer(buffer.data(), buffer.size()); | ||
| 123 | rb.Push<u32>(size); | ||
| 121 | } | 124 | } |
| 122 | 125 | ||
| 123 | void GetImageSize(Kernel::HLERequestContext& ctx) { | 126 | void GetImageSize(Kernel::HLERequestContext& ctx) { |
| 124 | LOG_DEBUG(Service_ACC, "called"); | 127 | LOG_DEBUG(Service_ACC, "called"); |
| 125 | constexpr u32 backup_jpeg_size = 107; | ||
| 126 | IPC::ResponseBuilder rb{ctx, 3}; | 128 | IPC::ResponseBuilder rb{ctx, 3}; |
| 127 | rb.Push(RESULT_SUCCESS); | 129 | rb.Push(RESULT_SUCCESS); |
| 128 | 130 | ||
| @@ -133,7 +135,7 @@ private: | |||
| 133 | "Failed to load user provided image! Falling back to built-in backup..."); | 135 | "Failed to load user provided image! Falling back to built-in backup..."); |
| 134 | rb.Push<u32>(backup_jpeg_size); | 136 | rb.Push<u32>(backup_jpeg_size); |
| 135 | } else { | 137 | } else { |
| 136 | rb.Push<u32>(std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE)); | 138 | rb.Push<u32>(SanitizeJPEGSize(image.GetSize())); |
| 137 | } | 139 | } |
| 138 | } | 140 | } |
| 139 | 141 | ||