FlUxIuS / V2Gdecoder

V2Gdecoder: encode and decode V2G messages on the fly
35 stars 13 forks source link

When encoding an XMI message, a parsing error occurs due to insufficient string buffers. #17

Closed dhje0ng closed 2 years ago

dhje0ng commented 2 years ago
{Format=XML, Accept=*/*, User-Agent=python-requests/2.27.1, Connection=keep-alive, Host=localhost:9000, Accept-Encoding=gzip, deflate, br, Content-Length=1331}
XML
<ns0:V2G_Message xmlns:ns0="urn:iso:15118:2:2013:MsgDef" xmlns:ns1="urn:iso:15118:2:2013:MsgHeader" xmlns:ns2="urn:iso:15118:2:2013:MsgBody" xmlns:ns3="urn:iso:15118:2:2013:MsgDataTypes">
  <ns0:Header>
    <ns1:SessionID>3B47AC6DB634437F</ns1:SessionID>
  </ns0:Header>
  <ns0:Body>
    <ns2:ServiceDiscoveryRes>
      <ns2:ResponseCode>OK</ns2:ResponseCode>
      <ns2:PaymentOptionList>
        <ns3:PaymentOption>ExternalPayment</ns3:PaymentOption>
      </ns2:PaymentOptionList>
      <ns2:ChargeService>
        <ns3:ServiceID>1</ns3:ServiceID>
        <ns3:ServiceName>AC_DC_Charging</ns3:ServiceName>
        <ns3:ServiceCategory>EVCharging</ns3:ServiceCategory>
        <ns3:ServiceScope>chargingServiceScope</ns3:ServiceScope>
        <ns3:FreeService>false</ns3:FreeService>
        <ns3:SupportedEnergyTransferMode>
          <ns3:EnergyTransferMode>AC_three_phase_core</ns3:EnergyTransferMode>
          <ns3:EnergyTransferMode>AC_single_phase_core</ns3:EnergyTransferMode>
          <ns3:EnergyTransferMode>DC_
[Fatal Error] :20:38: XML document structures must start and end within the same entity.
org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 38; XML document structures must start and end within the same entity.
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.fluxlus.V2Gdecoder.dataprocess.dataprocess.Xml2Exi(dataprocess.java:88)
    at com.fluxlus.V2Gdecoder.dataprocess.dataprocess.fuzzyExiEncoder(dataprocess.java:183)
    at com.fluxlus.V2Gdecoder.server.WorkerRunnable.run(WorkerRunnable.java:97)
    at java.base/java.lang.Thread.run(Thread.java:833)
^C%

The issue arises when the V2G Decoder is run on a web server.

If the length of the string is greater than or equal to the length of the specified buffer when encoding data with XMI, the data cannot be read and a Fatal error occurs.

The parseHTTPBody() function is called when parsing HTTP Body data, and the string buffer size should be modified as shown below.

        BufferedReader bufferedReader = new BufferedReader(test);
        char[] charBuffer = new char[4096]; // before new char[1024];
        int bytesRead;

To test it, correct the buffer and recompile it; it will work properly. Thank you.

FlUxIuS commented 2 years ago

Hello @dhje0ng,

Thank you for the post and the proposition to fix it!

Best regards, Sébastien