SOLR-13238: BlobHandler generates non-padded md5

This commit is contained in:
Jan Høydahl 2019-09-14 22:23:17 +02:00
parent ae570e4694
commit 31735eeb40
3 changed files with 14 additions and 4 deletions

View File

@ -206,6 +206,8 @@ Bug Fixes
* SOLR-13240: Fixed UTILIZENODE action resulting in IllegalArgumentException.
(Hendrik Haddorp, Richard Goodman, Tim Owen, shalin, noble, Christine Poerschke)
* SOLR-13238: BlobHandler generates non-padded md5 (Jeff Walraven via janhoy)
Other Changes
----------------------

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.invoke.MethodHandles;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.util.Collection;
@ -28,6 +27,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.codec.binary.Hex;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.Term;
@ -114,7 +114,7 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitial
}
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(payload.array(), payload.position(), payload.limit());
String md5 = new BigInteger(1, m.digest()).toString(16);
String md5 = new String(Hex.encodeHex(m.digest()));
int duplicateCount = req.getSearcher().count(new TermQuery(new Term("md5", md5)));
if (duplicateCount > 0) {

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
@ -86,6 +85,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
"type"),null));
checkBlobPost(baseUrl, cloudClient);
checkBlobPostMd5(baseUrl, cloudClient);
}
}
@ -108,6 +108,15 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
compareInputAndOutput(baseUrl + "/.system/blob/test/1?wt=filestream", bytarr, cloudClient);
}
static void checkBlobPostMd5(String baseUrl, CloudSolrClient cloudClient) throws Exception {
String blobName = "md5Test";
String stringValue = "MHMyugAGUxFzeqbpxVemACGbQ"; // Random string requires padding in md5 hash
String stringValueMd5 = "02d82dd5aabc47fae54ee3dd236ad83d";
postAndCheck(cloudClient, baseUrl, blobName, ByteBuffer.wrap(stringValue.getBytes(StandardCharsets.UTF_8)), 1);
MapWriter map = TestSolrConfigHandlerConcurrent.getAsMap(baseUrl + "/.system/blob/" + blobName, cloudClient);
assertEquals(stringValueMd5, map._getStr("response/docs[0]/md5", null));
}
public static void createSystemCollection(SolrClient client) throws SolrServerException, IOException {
CollectionAdminResponse response1;
CollectionAdminRequest.Create createCollectionRequest = CollectionAdminRequest.createCollection(".system",1,2);
@ -121,7 +130,6 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
String url;
MapWriter map = null;
List l;
final RTimer timer = new RTimer();
int i = 0;
for (; i < 150; i++) {//15 secs