Skip to content

Commit

Permalink
Fix frames being read out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
soir20 committed Nov 11, 2024
1 parent b66655a commit 07b8b13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ private AnimationMetadata readAnimationProperties(MetadataView metadata, int ima
private List<Frame> findFrames(NativeImage texture, int frameWidth, int frameHeight) {
List<Frame> frames = new ArrayList<>();

for (int minY = 0; minY < texture.getHeight(); minY += frameHeight) {
for (int minX = 0; minX < texture.getWidth(); minX += frameWidth) {
int finalMinX = minX;
int finalMinY = minY;
int framesY = texture.getHeight() / frameHeight;
int framesX = texture.getWidth() / frameWidth;
for (int frameY = 0; frameY < framesY; frameY++) {
for (int frameX = 0; frameX < framesX; frameX++) {
int finalMinX = frameX * frameWidth;
int finalMinY = frameY * frameHeight;
frames.add((x, y) -> texture.getPixelRGBA(finalMinX + x, finalMinY + y));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ public void analyze_HasPartsFrameWidthNotMultipleOfPartSize_InvalidMetadataExcep
"0", new MockMetadataView(ImmutableMap.of(
"width", 4,
"height", 10,
"texture", MOCK_TEXTURE.apply(10, 20),
"texture", MOCK_TEXTURE.apply(10, 22),
"x", 0,
"y", 0
))
Expand All @@ -1081,6 +1081,7 @@ public void analyze_HasPartsFrameWidthNotMultipleOfPartSize_InvalidMetadataExcep
assertEquals(10, metadata.parts().get(0).frameHeight());
assertEquals(0, metadata.parts().get(0).xInBase());
assertEquals(0, metadata.parts().get(0).yInBase());
assertEquals(4, metadata.parts().get(0).partFrames().orElseThrow().size());
}

@Test
Expand Down

0 comments on commit 07b8b13

Please sign in to comment.