From f1a08e7fb82e813ce6985460cc2606fc7b19ae13 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 14 Mar 2023 10:15:31 +0100 Subject: SSB encoding format validation --- .../java/org/uic/barcode/ssbFrame/SsbStations.java | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/main/java/org/uic/barcode/ssbFrame/SsbStations.java') diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java b/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java index 34fbbc3..e3b7654 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java @@ -2,6 +2,7 @@ package org.uic.barcode.ssbFrame; import org.uic.barcode.asn1.uper.BitBuffer; import org.uic.barcode.asn1.uper.ByteBitBuffer; +import org.uic.barcode.ticket.EncodingFormatException; public class SsbStations { @@ -23,9 +24,7 @@ public class SsbStations { protected String departureStationCode = " "; protected SsbStationCodeTable codeTable = SsbStationCodeTable.NRT; - - - public int encode(int offset, byte[] bytes) { + public int encode(int offset, byte[] bytes) throws EncodingFormatException { boolean isAlphaNumeric = false; @@ -42,16 +41,33 @@ public class SsbStations { offset++; if (isAlphaNumeric) { + if (departureStationCode.length() > 6) { + throw new EncodingFormatException("SSB departure station too long"); + } bits.putChar6String(offset,30, departureStationCode); offset = offset + 30; + + if (arrivalStationCode.length() > 6) { + throw new EncodingFormatException("SSB arrival station too long"); + } bits.putChar6String(offset,30, arrivalStationCode); offset = offset + 30; } else { bits.putInteger(offset, 4, codeTable.ordinal()); offset = offset + 4; - bits.putInteger(offset, 28, Integer.parseInt(departureStationCode)); + + int stationCode = Integer.parseInt(departureStationCode); + if (stationCode < 0 || stationCode > 9999999) { + throw new EncodingFormatException("SSB departure station code too long"); + } + bits.putInteger(offset, 28, stationCode); offset = offset + 28; - bits.putInteger(offset, 28, Integer.parseInt(arrivalStationCode)); + + stationCode = Integer.parseInt(arrivalStationCode); + if (stationCode < 0 || stationCode > 9999999) { + throw new EncodingFormatException("SSB arrival station code too long"); + } + bits.putInteger(offset, 28, stationCode); offset = offset + 28; } -- cgit v1.2.3