<commit_before>package com.ociweb.gl.impl;
import com.ociweb.gl.api.Headable;
import com.ociweb.gl.api.HeaderReader;
import com.ociweb.gl.api.Payloadable;
import com.ociweb.pronghorn.network.config.HTTPHeader;
import com.ociweb.pronghorn.pipe.MessageSchema;
import com.ociweb.pronghorn.pipe.Pipe;
import com.ociweb.pronghorn.pipe.util.hash.IntHashTable;
import com.ociweb.pronghorn.util.TrieParser;
import com.ociweb.pronghorn.util.TrieParserReader;

public class HTTPPayloadReader<S extends MessageSchema<S>> extends PayloadReader<S> implements HeaderReader {

	protected IntHashTable headerHash; //look up index of the header we want from its header id
	protected int paraIndexCount; //how may fields to skip over before starting
	protected TrieParser headerTrieParser; //look up header id from the header string bytes
	protected TrieParserReader reader = new TrieParserReader(0, true);
	
	
	public int headerId(byte[] header) {		
		int result = (int)TrieParserReader.query(reader, headerTrieParser, header, 0, header.length, Integer.MAX_VALUE);
		//System.out.println(result+"  "+new String(header));
		return result;
	}

	public HTTPPayloadReader(Pipe<S> pipe) {
		super(pipe);

	}


	public boolean openHeaderData(byte[] header, Headable headReader) {
		return openHeaderData(headerId(header), headReader);
	}

	public boolean openHeaderData(int headerId, Headable headReader) {
	
		if (headerId>=0) {
			int item = IntHashTable.getItem(headerHash, HTTPHeader.HEADER_BIT | headerId);
			
			if (item!=0) {				
				setPositionBytesFromStart(readFromEndLastInt(paraIndexCount + 1 + (0xFFFF & item)));
				
				headReader.read(this);//HTTPRequestReader
				
				return true;
			}
		}
		return false;
		
	}
	
	public boolean openPayloadData(Payloadable reader) {
		setPositionBytesFromStart(readFromEndLastInt(paraIndexCount + IntHashTable.count(headerHash)));
		reader.read(this);//even when we have zero length...
		return true;
	}



	
}<commit_msg>added bounds check in payload reader<commit_after>package com.ociweb.gl.impl;
import com.ociweb.gl.api.Headable;
import com.ociweb.gl.api.HeaderReader;
import com.ociweb.gl.api.Payloadable;
import com.ociweb.pronghorn.network.config.HTTPHeader;
import com.ociweb.pronghorn.pipe.MessageSchema;
import com.ociweb.pronghorn.pipe.Pipe;
import com.ociweb.pronghorn.pipe.util.hash.IntHashTable;
import com.ociweb.pronghorn.util.TrieParser;
import com.ociweb.pronghorn.util.TrieParserReader;

public class HTTPPayloadReader<S extends MessageSchema<S>> extends PayloadReader<S> implements HeaderReader {

	protected IntHashTable headerHash; //look up index of the header we want from its header id
	protected int paraIndexCount; //how may fields to skip over before starting
	protected TrieParser headerTrieParser; //look up header id from the header string bytes
	protected TrieParserReader reader = new TrieParserReader(0, true);
	
	
	public int headerId(byte[] header) {		
		int result = (int)TrieParserReader.query(reader, headerTrieParser, header, 0, header.length, Integer.MAX_VALUE);
		//System.out.println(result+"  "+new String(header));
		return result;
	}

	public HTTPPayloadReader(Pipe<S> pipe) {
		super(pipe);

	}


	public boolean openHeaderData(byte[] header, Headable headReader) {
		return openHeaderData(headerId(header), headReader);
	}

	public boolean openHeaderData(int headerId, Headable headReader) {
	
		if (headerId>=0) {
			int item = IntHashTable.getItem(headerHash, HTTPHeader.HEADER_BIT | headerId);
			
			if (item!=0) {				
								
				int itemIndex = 0xFFFF & item;
				
				int posFromStart = readFromEndLastInt(paraIndexCount + 1 + itemIndex);
				assert(posFromStart<available()) : "index position "+posFromStart+" is out of bounds "+available();
				assert(posFromStart>=0) : "index position must be zero or positive";
				
				setPositionBytesFromStart(posFromStart);
				
				headReader.read(this);//HTTPRequestReader
				
				return true;
			}
		}
		return false;
		
	}
	
	public boolean openPayloadData(Payloadable reader) {
		setPositionBytesFromStart(readFromEndLastInt(paraIndexCount + IntHashTable.count(headerHash)));
		reader.read(this);//even when we have zero length...
		return true;
	}



	
}
{'fraction_non_alphanumeric': 0.10116917203531377, 'fraction_numerical': 0.003101884991648771, 'mean_word_length': 4.726775956284153, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5321783', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1288, 'n_words': 310}