Skip to content

Commit 8140914

Browse files
committed
Fix reading broken DC6 again
See 811c452 for more details Ref AbyssEngine#158
1 parent b0adec1 commit 8140914

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/Abyss/DataTypes/DC6.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ void DC6::setPalette(const Palette &palette) {
8282

8383
const auto &frameData = frame.getFrameData();
8484
while (process) {
85+
if (offset >= frameData.size()) {
86+
throw std::runtime_error("Data overrun while decoding DC6 frame.");
87+
}
8588
const auto b = frameData[offset];
8689
offset++;
8790

@@ -102,6 +105,9 @@ void DC6::setPalette(const Palette &palette) {
102105
}
103106
case eScanlineType::RunOfOpaquePixels: {
104107
for (auto i = 0; i < static_cast<int>(b); i++) {
108+
if (offset >= frameData.size()) {
109+
throw std::runtime_error("Data overrun while decoding DC6 frame.");
110+
}
105111
const auto paletteIndex = static_cast<int>(frameData[offset]);
106112
const auto &paletteColor = palette.getEntries()[paletteIndex];
107113
const auto pixel = static_cast<uint32_t>(paletteColor.getBlue() << 24 | paletteColor.getGreen() << 16 | paletteColor.getRed() << 8 | 0xFF);

src/Abyss/DataTypes/DC6Frame.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ DC6Frame::DC6Frame(Streams::StreamReader &stream) {
1414
_nextBlock = stream.readUInt32();
1515
_length = stream.readUInt32();
1616

17-
_frameData.resize(_length);
18-
stream.readBytes(_frameData);
19-
20-
_terminator.resize(DC6TerminatorSize);
21-
stream.readBytes(_terminator);
17+
_frameData.resize(_length + DC6TerminatorSize);
18+
stream.readBytes(_frameData);
2219
}
2320

2421
uint32_t DC6Frame::getFlipped() const { return _flipped; }
@@ -39,6 +36,4 @@ uint32_t DC6Frame::getLength() const { return _length; }
3936

4037
const std::vector<std::byte>& DC6Frame::getFrameData() const { return _frameData; }
4138

42-
const std::vector<std::byte>& DC6Frame::getTerminator() const { return _terminator; }
43-
4439
} // namespace Abyss::DataTypes

src/Abyss/DataTypes/DC6Frame.h

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class DC6Frame {
2222
uint32_t _nextBlock{};
2323
uint32_t _length{};
2424
std::vector<std::byte> _frameData{};
25-
std::vector<std::byte> _terminator{};
2625

2726
public:
2827
explicit DC6Frame(Streams::StreamReader& stream);
@@ -35,7 +34,6 @@ class DC6Frame {
3534
[[nodiscard]] uint32_t getNextBlock() const;
3635
[[nodiscard]] uint32_t getLength() const;
3736
[[nodiscard]] const std::vector<std::byte>& getFrameData() const;
38-
[[nodiscard]] const std::vector<std::byte>& getTerminator() const;
3937
};
4038

4139
} // namespace Abyss::DataTypes

0 commit comments

Comments
 (0)