Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Linear pattern index incrementing above array length #2626

Merged
merged 2 commits into from Mar 24, 2024

Conversation

Zeranny
Copy link
Contributor

@Zeranny Zeranny commented Mar 16, 2024

Overview

When running async the #linear pattern can increment index above the length of the patternsArray.
This tends not to happen on small operations.

[14:49:33 ERROR]: [com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent] Catching
java.lang.ArrayIndexOutOfBoundsException: Index 9 out of bounds for length 3
        at com.fastasyncworldedit.core.function.pattern.LinearBlockPattern.apply(LinearBlockPattern.java:37) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.sk89q.worldedit.function.pattern.Pattern.applyBlock(Pattern.java:59) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.fastasyncworldedit.core.extent.filter.LinkedFilter.applyBlock(LinkedFilter.java:28) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.fastasyncworldedit.core.extent.filter.block.CharFilterBlock.filter(CharFilterBlock.java:130) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.sk89q.worldedit.regions.Region.filter(Region.java:367) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.sk89q.worldedit.regions.Region.filter(Region.java:301) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.sk89q.worldedit.regions.CuboidRegion.filter(CuboidRegion.java:762) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock.filter(ChunkFilterBlock.java:88) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder.filterBlocks(ChunkHolder.java:903) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.fastasyncworldedit.core.queue.IQueueExtent.apply(IQueueExtent.java:144) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent.lambda$apply$0(ParallelQueueExtent.java:162) ~[FastAsyncWorldEdit-Bukkit-2.9.1-SNAPSHOT.jar:?]
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source) ~[?:?]
        at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) ~[?:?]
        at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source) ~[?:?]
        at java.util.concurrent.ForkJoinPool.scan(Unknown Source) ~[?:?]
        at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) ~[?:?]
        at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) ~[?:?]

Replication steps for error:

  1. Select a decently large selection (64^3 seems enough)
  2. Set a linear pattern such as //set #linear[1,2,3]
  3. Chat ingame may report a success but the operation will either fully or partially fail with OoB errors in console as above

Description

Changes the index calculation to always modulo with the patternsArray length to prevent an Out of Bounds exception.

While this fixes the error, the linear pattern itself is quite messy when running async:

2024-03-16_15 31 18

I'm not sure if it's worth changing anything, as if you were to make it ordered then it would just look like the #linear3d pattern.

Submitter Checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter Checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic branch (/feature/fix/docs/ branch (right side)) and not your main branch.
    Options
  2. Ensure that the pull request title represents the desired changelog entry.
    Options
  3. New public fields and methods are annotated with @since TODO.
    Options
  4. I read and followed the contribution guidelines.
    Options

@Zeranny Zeranny requested a review from a team as a code owner March 16, 2024 15:34
@github-actions github-actions bot added the Bugfix This PR fixes a bug label Mar 16, 2024
@dordsor21
Copy link
Member

We can use the Filter#fork method to correctly handle async pattern access

@Zeranny
Copy link
Contributor Author

Zeranny commented Mar 17, 2024

I added the fork method (copy pasta from #2633)

The resulting pattern is more ordered, but it's still odd. I'm kinda questioning what purpose #linear serves

2024-03-17_22 11 00

@SirYwell
Copy link
Member

It's behavior fully depends on iteration order, but yeah, I'm not sure if it's actually useful in any scenario.

@dordsor21
Copy link
Member

dordsor21 commented Mar 19, 2024

On none-parallel operations like fill, sphere (I think?) etc. it'd work?

I would also say close this in favour of #2633 as that addresses the issue in the rest of the patterns too

@Zeranny
Copy link
Contributor Author

Zeranny commented Mar 19, 2024

On none-parallel operations like fill, sphere (I think?) etc. it'd work?

I would also say close this in favour of #2633 as that addresses the issue in the rest of the patterns too

It looks different with spheres, but still doesn't seem to useful:

2024-03-19_11 31 49

I would agree the thread safe part can be covered by #2633, however if I remove the overflow safety and just have fork, I can still get the out of bounds error, so that portion of this PR is still relevant.

@dordsor21 dordsor21 requested a review from a team March 23, 2024 14:43
@dordsor21 dordsor21 merged commit c10f58a into IntellectualSites:main Mar 24, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix This PR fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants