fix(batch): EgovFlatFileByteReader 공유 가변 static LINE_CRLF 동시성·데이터 손상 제거#263
Open
z3rotig4r wants to merge 1 commit into
Open
fix(batch): EgovFlatFileByteReader 공유 가변 static LINE_CRLF 동시성·데이터 손상 제거#263z3rotig4r wants to merge 1 commit into
z3rotig4r wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
문제
EgovFlatFileByteReader.LINE_CRLF는public static int로 선언된 공유 가변 전역인데, 인스턴스 settersetOsType()이 이 전역을 직접 덮어쓴다. 이 단일 전역 값이 reader의 고정길이 버퍼 크기(new byte[length + LINE_CRLF],reader.read(..., length + LINE_CRLF))와EgovFixedByteTokenizer의 CRLF 차감(byteString.length - LINE_CRLF)에 동시에 쓰인다.osType이 서로 다른 두 reader 빈(UNIX·WINDOWS)이 한 컨텍스트에 공존하면, 마지막
setOsType호출이 전역을 덮어쓴다(last-writer-wins). 그 결과 다른 빈의 고정길이 필드 경계가 1바이트씩 밀려 무성(silent) 데이터 손상으로 이어진다. CWE-362(경합 조건)·CWE-366(공유 변수 경합)·CWE-471에 해당한다.수정
전역 가변 static을 인스턴스 상태로 옮긴다.
public static int LINE_CRLF제거 →private int lineCrlf(기본값 WINDOWS=2). 버퍼 사이징은 인스턴스 필드를 참조하고getLineCrlf()를 추가한다.private int lineCrlf(기본값 2)와setLineCrlf(int)·setOsType(String)를 둔다.빈마다 값을 독립으로 보유하므로 상호 오염이 사라진다.
동작 보존
단일 reader의 기본/WINDOWS 구성은 값(2)이 그대로라 출력 바이트가 동일하다. CRLF를 차감하지 않는 형제 클래스
EgovFixedByteLengthTokenizer는 손대지 않았다.주의(후방호환)
기존에는 reader에
setOsType("UNIX")를 한 번 호출하면 공유 static을 통해 tokenizer의 차감값도 1로 전파됐다. 분리 이후에는 UNIX 고정길이 잡의 경우 tokenizer에도setOsType("UNIX")(또는setLineCrlf(1))를 명시 설정해야 한다. reader만 UNIX로 두면 tokenizer가 기본값 2로 차감해IncorrectLineLengthException이 발생한다. 또한public static LINE_CRLF필드가 제거되므로, 외부에서 이 필드를 직접 참조하던 코드가 있다면 컴파일에 영향을 준다.테스트
신규 4건을 추가했다.
mvn -pl Batch/org.egovframe.rte.bat.core -am test실행, 해당 모듈 테스트 18건 모두 통과.