private void verifyLocalFilePath ( String localFilePathFromGS ) throws SnowflakeSQLException { if ( command == null ) { logger . error ( "null command" ) ; return ; } if ( command . indexOf ( FILE_PROTOCOL ) < 0 ) { logger . error ( "file:// prefix not found in command: {}" , command ) ; return ; } int localFilePathBeginIdx = command . indexOf ( FILE_PROTOCOL ) + FILE_PROTOCOL . length ( ) ; boolean isLocalFilePathQuoted = ( localFilePathBeginIdx > FILE_PROTOCOL . length ( ) ) && ( command . charAt ( localFilePathBeginIdx - 1 - FILE_PROTOCOL . length ( ) ) == ' ' ) ; // the ending index is exclusive int localFilePathEndIdx = 0 ; String localFilePath = "" ; if ( isLocalFilePathQuoted ) { // look for the matching quote localFilePathEndIdx = command . indexOf ( "'" , localFilePathBeginIdx ) ; if ( localFilePathEndIdx > localFilePathBeginIdx ) { localFilePath = command . substring ( localFilePathBeginIdx , localFilePathEndIdx ) ; } // unescape backslashes to match the file name from GS localFilePath = localFilePath . replaceAll ( "\\\\\\\\" , "\\\\" ) ; } else { // look for the first space or new line or semi colon List < Integer > indexList = new ArrayList <> ( ) ; char [ ] delimiterChars = { ' ' , ' ' , ' ' } ; for ( int i = 0 ; i < delimiterChars . length ; i ++ ) { int charIndex = command . indexOf ( delimiterChars [ i ] , localFilePathBeginIdx ) ; if ( charIndex != - 1 ) { indexList . add ( charIndex ) ; } } localFilePathEndIdx = indexList . isEmpty ( ) ? - 1 : Collections . min ( indexList ) ; if ( localFilePathEndIdx > localFilePathBeginIdx ) { localFilePath = command . substring ( localFilePathBeginIdx , localFilePathEndIdx ) ; } else if ( localFilePathEndIdx == - 1 ) { localFilePath = command . substring ( localFilePathBeginIdx ) ; } } if ( ! localFilePath . isEmpty ( ) && ! localFilePath . equals ( localFilePathFromGS ) ) { throw new SnowflakeSQLException ( SqlState . INTERNAL_ERROR , ErrorCode . INTERNAL_ERROR . getMessageCode ( ) , "Unexpected local file path from GS. From GS: " + localFilePathFromGS + ", expected: " + localFilePath ) ; } else if ( localFilePath . isEmpty ( ) ) { logger . debug ( "fail to parse local file path from command: {}" , command ) ; } else { logger . trace ( "local file path from GS matches local parsing: {}" , localFilePath ) ; } }
A helper method to verify if the local file path from GS matches what s parsed locally . This is for security purpose as documented in SNOW - 15153 .