This study aims to study the safety of oil and gas pipelines under stress corrosion conditions and grasp the corrosion damage situation timely and accurately. Consequently, a non-destructive testing method combining magnetic flux leakage testing technology and a kernel function extreme learning machine improved by genetic algorithm (GA-KELM) is proposed. Firstly, the variation of the corrosion defect dimension and profile with time is obtained by numerical simulation. At the same time, the distribution of the magnetic flux leakage signal under different defect conditions is analyzed and studied. Finally, feature selection is carried out on the magnetic flux leakage signal distribution curve, and GA-KELM is used to predict the depth and length of corrosion defects so as to realize the non-destructive testing of the pipeline defects. The results show that different geometric features result in different magnetic flux leakage signal distributions. There is a corresponding relationship between the defect dimension and extreme value, area, and peak width of the magnetic flux leakage signal distribution curve. The GA-KELM prediction model can effectively predict the depth and length of corrosion defects, and the prediction accuracy is better than the traditional extreme learning machine prediction model.