Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/dermotte/liresolr
This is a Solr plugin for the LIRE content based image retrieval library, so basically it's for indexing images and then finding similar (looking) ones. The original library can be found at Github
The LIRE Solr plugin includes a RequestHandler for searching, an EntityProcessor for indexing, a ValeSource Parser for content based re-ranking and a parallel indexing application.
An outdated demo can be found at http://demo-itec.uni-klu.ac.at/liredemo/. If you want to give it a try yourself, there is a docker image, which you use to run a pre-configured core on a Solr server.
If you need help on the plugin, please use the mailing list at lire-dev mailing list to ask questions. Additional documentation is available on src/main/docs/index.md If you need help with your project, please contact me, we also offer consulting services.
If you use LIRE Solr for scientific purposes, please cite the following paper:
Mathias Lux and Glenn Macstravic "The LIRE Request Handler: A Solr Plug-In for Large Scale Content Based Image Retrieval." MultiMedia Modeling. Springer International Publishing, 2014. Springer
The request handler supports the following different types of queries
Supported values for feature field parameters, e.g. lireq?field=cl_ha:
The field parameter (partially) works with the LIRE request handler:
Returns randomly chosen images from the index. While it does not seem extremely helpful, it's actuall great to find images to be used for example queries.
Parameters:
Returns images that look like the one with the given ID.
Parameters:
Returns images that look like the one found at the given URL.
Parameters:
Returns an image that looks like the one the given features were extracted. This method is used if the client extracts the features from the image, which makes sense if the image should not be submitted.
Parameters:
Extracts the histogram and the hashes of an image for use with the lire sorting function.
Parameters:
First run the dist task by gradle build
command in liresolr folder (gradle should be installed for this) to create a plugin jar. Then copy jars: cp ./build/libs/*.jar ./lib/*.jar /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/
. Then add the new request handler has to be registered in the solrconfig.xml
file:
<requestHandler name="/lireq" class="net.semanticmetadata.lire.solr.LireRequestHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
</lst>
</requestHandler>
Use of the request handler is detailed above.
You'll also need the respective fields in the schema.xml
(in the base configuration in Solr 6.3.0 it is called managed-schema
) file:
<!-- file path for ID, should be there already -->
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<!-- the title of the image, e.g. the file name -->
<field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<!-- the url where the image is to be downloaded -->
<field name="imgurl" type="string" indexed="true" stored="true" multiValued="false"/>
<!-- Dynamic fields for LIRE Solr -->
<dynamicField name="*_ha" type="text_ws" indexed="true" stored="false"/> <!-- if you are using BitSampling -->
<dynamicField name="*_ms" type="text_ws" indexed="true" stored="false"/> <!-- if you are using Metric Spaces Indexing -->
<dynamicField name="*_hi" type="binaryDV" indexed="false" stored="true"/>
Do not forget to add the custom field at the very same file:
<fieldtype name="binaryDV" class="net.semanticmetadata.lire.solr.BinaryDocValuesField"/>
There is also a sort function based on LIRE. The function parser needs to be added to the
solarconfig.xml
file like this:
<valueSourceParser name="lirefunc"
class="net.semanticmetadata.lire.solr.LireValueSourceParser" />
Then the function lirefunc(arg1,arg2)
is available for function queries. Two arguments are necessary and are defined as:
LireFeature.getByteRepresentation()
and by Base64 encoding the resulting byte[] data.Note that if you send the parameters using an URL you might take extra care of the URL encoding, ie. white space, the "=" sign, etc.
Examples:
[solrurl]/select?q=*:*&fl=id,lirefunc(cl,"FQY5DhMYDg...AQEBA=")
– adding the distance to the reference image to the results[solrurl]/select?q=*:*&sort=lirefunc(cl,"FQY5DhMYDg...AQEBA=")+asc
– sorting the results based on the distance to the reference imageIf you extract the features yourself, use code like his one:
// ColorLayout
ColorLayout cl = new ColorLayout();
cl.extract(ImageIO.read(new File("...")));
String arg1 = "cl";
String arg2 = Base64.encode(cl.getByteArrayRepresentation());
// PHOG
PHOG ph = new PHOG();
ph.extract(ImageIO.read(new File("...")));
String arg1 = "ph";
String arg2 = Base64.encode(ph.getByteArrayRepresentation());
Check ParallelSolrIndexer.java
for indexing. It creates XML documents (either one per image or one single large file)
to be sent to the Solr Server.
This help text is shown if you start the ParallelSolrIndexer with the '-h' option.
$> ParallelSolrIndexer -i <infile> [-o <outfile>] [-n <threads>] [-f] [-p] [-m <max_side_length>] [-r <full class name>] \\
[-y <list of feature classes>]
Note: if you don't specify an outfile just ".xml" is appended to the input image for output. So there will be one XML file per image. Specifying an outfile will collect the information of all images in one single file.
The infile gives one image per line with the full path. You can create an infile easily on Windows with running in the parent directory of the images
$> dir /s /b *.jpg > infile.txt
On linux just use find, grep and whatever you find appropriate. With find it'd look like this assuming that you run it from the root directory:
$> find /[path-to-image-base-dir]/ -name *.jpg
The outfile
from ParallelIndexer
has to be send to the Solr server. Assuming the Solr server is local you may use
curl.exe http://localhost:8983/solr/lire/update -H "Content-Type: text/xml" --data-binary "<delete><query>*:*</query></delete>"
curl.exe http://localhost:8983/solr/lire/update -H "Content-Type: text/xml" --data-binary @outfile.xml
curl.exe http://localhost:8983/solr/lire/update -H "Content-Type: text/xml" --data-binary "<commit/>"
You need to commit you changes! If your outfile exceeds 500MB, curl might complain. Then use split to cut it into pieces and repair the root tags (<add>
and </add>
). Here is an example how to do that with bash & linux (use Git Bash on Windows) under the assumption that the split leads to files {0, 1, 2, ..., n}
$> split -l 100000 -d images.xml images_
$> echo "</add>" >> images_00
$> echo "</add>" >> images_01
...
$> echo "</add>" >> images_<n-1>
$> sed -i.old '1s;^;<add>;' images_01
$> sed -i.old '1s;^;<add>;' images_02
...
$> sed -i.old '1s;^;<add>;' images_<n>
For small output files you may use the file upload option in the Solr admin interface.
Another way is to use the LireEntityProcessor. Then you have to reference the solr-data-config.xml file in the solrconfig.xml, and then give the configuration for the EntityProcessor like this:
<dataConfig>
<dataSource name ="bin" type="BinFileDataSource" />
<document>
<entity name="f"
processor="FileListEntityProcessor"
transformer="TemplateTransformer"
baseDir="D:\Java\Projects\Lire\testdata\wang-1000\"
fileName=".*jpg"
recursive="true"
rootEntity="false" dataSource="null" onError="skip">
<entity name="lire-test" processor="net.semanticmetadata.lire.solr.LireEntityProcessor" url="${f.fileAbsolutePath}" dataSource="bin" onError="skip">
<field column="id"/>
<field column="cl_ha"/>
<field column="cl_hi"/>
<field column="ph_ha"/>
<field column="ph_hi"/>
<field column="oh_ha"/>
<field column="oh_hi"/>
<field column="jc_ha"/>
<field column="jc_hi"/>
<field column="eh_ha"/>
<field column="eh_hi"/>
</entity>
</entity>
</document>
</dataConfig>
Mathias Lux, 2016-12-17
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.