Bug Report • Title: Image Resizer Code Issue - Lack of Input Validation for Custom Dimensions

• Title: Image Resizer Code Issue - Lack of Input Validation for Custom Dimensions
• Description: The image resizer code does not properly validate user input for custom width and height dimensions. This allows users to enter invalid values (e.g., negative numbers, zero, non-numeric characters), leading to unexpected behavior and potential errors. The script should validate these inputs before attempting to resize the image.
• Steps to Reproduce:

  1. Upload an image using the “Choose File” input.

  2. In the “Custom Dimensions” section, enter a negative number or zero for either the “Width” or “Height” field.

  3. Click the “Apply” button.

  4. Observe the canvas and the preview area.
    • Expected Behavior: The script should validate the width and height inputs. If a user enters an invalid value (negative number, zero, or non-numeric input), the script should prevent the resizing operation and display a clear error message to the user, indicating the acceptable input format (positive integers). The canvas and preview should not be updated with the invalid dimensions.
    • Actual Behavior: The script attempts to use the provided dimensions, even if they are invalid. This can lead to several problems:
    o If a negative number is entered, the crop box may be positioned or sized incorrectly, leading to unexpected cropping or no cropping at all.
    o If zero is entered, the crop box dimensions become zero, effectively making the image disappear from the preview.
    o If non-numeric input is entered, the parseInt function will return NaN (Not a Number), which can cause errors in subsequent calculations or prevent the resizing from working correctly.
    • Environment: Tested on Google Chrome (Version 133.0.6943.98), Windows 10 64-bit operating system.
    • Severity: Medium - While the issue doesn’t crash the application, it prevents the user from reliably using the custom dimensions feature and can lead to frustration and confusion. (REVIEW AND ADJUST IF NECESSARY)
    • Code Snippet: The issue is located in the setCustomDimensions function:
    JavaScript
    setCustomDimensions(width, height) {
    this.cropBox.width = width || parseInt(document.getElementById(‘customWidth’).value);
    this.cropBox.height = height || parseInt(document.getElementById(‘customHeight’).value);
    // … rest of the function
    }
    This function does not check if the parsed width and height values are valid positive integers.
    Recommended Fix:
    Add input validation within the setCustomDimensions function before assigning values to this.cropBox.width and this.cropBox.height. Here’s an example of how you could implement the validation:
    JavaScript
    setCustomDimensions(width, height) {
    const widthInput = parseInt(document.getElementById(‘customWidth’).value);
    const heightInput = parseInt(document.getElementById(‘customHeight’).value);

    if (isNaN(widthInput) || widthInput <= 0) {
    alert(“Width must be a positive integer.”); // Or a more user-friendly error message
    return; // Stop the function if input is invalid
    }

    if (isNaN(heightInput) || heightInput <= 0) {
    alert(“Height must be a positive integer.”); // Or a more user-friendly error message
    return; // Stop the function if input is invalid
    }

    this.cropBox.width = width || widthInput;
    this.cropBox.height = height || heightInput;
    // … rest of the function
    }
    This improved version checks if the inputs are valid numbers and greater than zero. If not, it displays an alert and returns from the function, preventing the resizing operation from proceeding with invalid data. You could also consider adding more robust input validation (e.g., using regular expressions) and providing more specific error messages.
    Final Reminder: This is a template. You must review the report carefully, especially the severity assessment, and customize it for the specific bug bounty program you are targeting. I cannot emphasize this enough. Submitting a report without understanding its contents is not a good practice. Test the suggested fix yourself if possible. Good luck!

Hi there,

Welcome to the forum.

For your post, I suggest that https://issuetracker.google.com/ might be the better tool.

Cheers