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

Array bounds issues in PixelAudioMapper #13

Open
Ignotus-mago opened this issue Jul 18, 2024 · 0 comments
Open

Array bounds issues in PixelAudioMapper #13

Ignotus-mago opened this issue Jul 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Ignotus-mago
Copy link
Owner

Ignotus-mago commented Jul 18, 2024

As already noted in other issues and in the comments for PixelAudioMapper, when signalPos + length > img.length we are in trouble. Even more so if signalPos > img.length. There are several ways to handle this:

  1. Just throw the error and teach the coder on the other end to check values before calling.
  2. Reset length if it's too big, but post a warning to System.out about it.
  3. If signalPos is too big, return null.

If this is meant to be performance software, gracefully failing as in 2. is better than wrist-slapping as in 1. I don't particularly want to oblige end users to check for null returns, but they can get a warning and the null array can cause the next error if they continue without checking for null.

All of this checking comes before running loops, so it's very quick to do. It looks like this:

// We can have an error condition if signalPos + length exceeds img.length! 
// If signalPos exceeds length, we return null. Let the caller take note and remedy the problem.
if (signalPos + length > img.length) {
  length = img.length - signalPos ;
  System.out.println("WARNING! signalPos + length exceeded img array length. Length was trimmed to "+ length);
}
if (signalPos >= img.length) {
  System.out.println("WARNING! signalPos "+ signalPos +" exceeded img length "+ img.length +". Returning null.");
  return null;
}
@Ignotus-mago Ignotus-mago added the enhancement New feature or request label Jul 18, 2024
Ignotus-mago added a commit that referenced this issue Jul 18, 2024
Using signalPos to index all "pluck" and "plant" methods. Added code to handle potential array bounds errors as gracefully as possible. See issue #12 and issue #13.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant