Exploit database

GH-9a017fa45abc7e1f8f6ba6e1285cae54

iplayforsg/cve-2023-51444

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-51444

1 source

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files10

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

wcs/src/main/java/org/geoserver/wcs/responses/IMGCoverageResponseDelegate.java

Java · 3,660 bytes
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
 * (c) 2001 - 2013 OpenPlans
 * This code is licensed under the GPL 2.0 license, available at the root
 * application directory.
 */
package org.geoserver.wcs.responses;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.geoserver.config.GeoServer;
import org.geoserver.platform.ServiceException;
import org.geoserver.util.IOUtils;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.image.WorldImageWriter;
import org.opengis.coverage.grid.Format;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterValueGroup;

/**
 * Encodes coverages in "world image" formats, png, jpeg and gif.
 *
 * <p>Notice that depending on the underlying coverage structure this is not always possible.
 *
 * @author $Author: Alessio Fabiani ([email protected]) $ (last modification)
 * @author $Author: Simone Giannecchini ([email protected]) $ (last modification)
 */
public class IMGCoverageResponseDelegate extends BaseCoverageResponseDelegate
        implements CoverageResponseDelegate {

    @SuppressWarnings("serial")
    public IMGCoverageResponseDelegate(GeoServer geoserver) {
        super(
                geoserver,
                Arrays.asList(
                        "png", "jpeg", "JPEG", "PNG", "image/png", "image/jpeg"), // output formats
                new HashMap<String, String>() { // file extensions
                    {
                        put("png", "png");
                        put("jpeg", "jpeg");
                        put("JPEG", "jpeg");
                        put("PNG", "png");
                        put("image/png", "png");
                        put("image/jpeg", "jpeg");
                    }
                },
                new HashMap<String, String>() { // mime types
                    {
                        put("png", "image/png");
                        put("jpeg", "image/jpeg");
                        put("PNG", "image/png");
                        put("JPEG", "image/jpeg");
                        put("image/png", "image/png");
                        put("image/jpeg", "image/jpeg");
                    }
                });
    }

    @Override
    @SuppressWarnings("PMD.UseTryWithResources")
    public void encode(
            GridCoverage2D sourceCoverage,
            String outputFormat,
            Map<String, String> econdingParameters,
            OutputStream output)
            throws ServiceException, IOException {
        if (sourceCoverage == null) {
            throw new IllegalStateException(
                    "It seems prepare() has not been called or has not succeed");
        }

        final WorldImageWriter writer = new WorldImageWriter(output);

        // writing parameters for Image
        final Format writerParams = writer.getFormat();
        final ParameterValueGroup writeParameters = writerParams.getWriteParameters();
        final ParameterValue<?> format = writeParameters.parameter("Format");
        format.setValue(getFileExtension(outputFormat));

        try {
            // writing
            writer.write(sourceCoverage, new GeneralParameterValue[] {format});
            output.flush();
        } finally {

            // freeing everything
            IOUtils.closeQuietly(output);

            try {
                writer.dispose();
            } catch (Throwable e) {
                // eat me
            }
            sourceCoverage.dispose(true);
        }
    }
}