Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Fix Base64 Error: ArrayIndexOutOfBoundsException #942

Merged
merged 4 commits into from
May 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main/java/com/spotify/docker/client/DefaultDockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -165,6 +166,8 @@
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
Expand All @@ -183,7 +186,6 @@
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.RequestEntityProcessing;
import org.glassfish.jersey.internal.util.Base64;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -2722,9 +2724,9 @@ private String authHeader(final RegistryAuth registryAuth) throws DockerExceptio
return "null";
}
try {
return Base64.encodeAsString(ObjectMapperProvider
return Base64.encodeBase64String(ObjectMapperProvider
.objectMapper()
.writeValueAsString(registryAuth));
.writeValueAsBytes(registryAuth));
} catch (JsonProcessingException ex) {
throw new DockerException("Could not encode X-Registry-Auth header", ex);
}
Expand All @@ -2750,7 +2752,7 @@ private String authRegistryHeader(final RegistryConfigs registryConfigs)
authRegistryJson = "{\"auths\":" + authRegistryJson + "}";
}

return Base64.encodeAsString(authRegistryJson);
return Base64.encodeBase64String(authRegistryJson.getBytes(StandardCharsets.UTF_8));
} catch (JsonProcessingException | InterruptedException ex) {
throw new DockerException("Could not encode X-Registry-Config header", ex);
}
Expand Down